Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it L'avatar di Ironmax
    Registrato dal
    Dec 2008
    Messaggi
    1,026

    Problemi di flusso con Hibernate e PostgreSQL

    Salve.
    Sto tentando di creare una tabella ed inserire dei dati in postgresql tramite il framework Hibernate, ma continua a dare questo errore:
    codice:
    ott 14, 2016 7:17:45 PM org.hibernate.Version logVersion
    INFO: HHH000412: Hibernate Core {5.0.9.Final}
    ott 14, 2016 7:17:45 PM org.hibernate.cfg.Environment <clinit>
    INFO: HHH000206: hibernate.properties not found
    ott 14, 2016 7:17:45 PM org.hibernate.cfg.Environment buildBytecodeProvider
    INFO: HHH000021: Bytecode provider name : javassist
    ott 14, 2016 7:17:45 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
    INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
    ott 14, 2016 7:17:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
    WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
    ott 14, 2016 7:17:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/provahib]
    ott 14, 2016 7:17:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001001: Connection properties: {user=postgres, password=****, pool_size=1}
    ott 14, 2016 7:17:45 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
    INFO: HHH10001003: Autocommit mode: false
    ott 14, 2016 7:17:45 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
    INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
    ott 14, 2016 7:17:46 PM org.hibernate.dialect.Dialect <init>
    INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQLDialect
    ott 14, 2016 7:17:46 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
    INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
    ott 14, 2016 7:17:46 PM org.hibernate.type.BasicTypeRegistry register
    INFO: HHH000270: Type registration [java.util.UUID] overrides previous : org.hibernate.type.UUIDBinaryType@4b2bac3f
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: drop table if exists User cascade
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: HHH000389: Unsuccessful: drop table if exists User cascade
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: ERRORE: errore di sintassi a o presso "User"
      Posizione: 22
    Hibernate: create table User (userId int4 not null, userName varchar(255), primary key (userId))
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: HHH000389: Unsuccessful: create table User (userId int4 not null, userName varchar(255), primary key (userId))
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: ERRORE: errore di sintassi a o presso "User"
      Posizione: 14
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport execute
    INFO: HHH000230: Schema export complete
    Hibernate: insert into User (userName, userId) values (?, ?)
    ott 14, 2016 7:17:47 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    WARN: SQL Error: 0, SQLState: 42601
    ott 14, 2016 7:17:47 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
    ERROR: ERRORE: errore di sintassi a o presso "User"
      Posizione: 13
    ott 14, 2016 7:17:47 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
    INFO: HHH000010: On release of batch it still contained JDBC statements
    ott 14, 2016 7:17:47 PM org.hibernate.internal.SessionImpl$5 mapManagedFlushFailure
    ERROR: HHH000346: Error during managed flush [could not execute statement]
    Exception in thread "main" org.hibernate.exception.SQLGrammarException: could not execute statement
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
        at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2886)
        at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3386)
        at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:560)
        at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:434)
        at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:337)
        at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
        at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1282)
        at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:465)
        at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2963)
        at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2339)
        at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
        at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
        at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
        at org.massimo.hibernate.HibernateTest.main(HibernateTest.java:20)
    Caused by: org.postgresql.util.PSQLException: ERRORE: errore di sintassi a o presso "User"
      Posizione: 13
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2284)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2003)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:200)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:424)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:161)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:133)
        at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
        ... 18 more
    Questo è il file di configurazione:
    codice:
    <!DOCTYPE hibernate-configuration PUBLIC
            "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
            "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
    
    <hibernate-configuration>
        <session-factory>
            <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
            <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
            <property name="hibernate.connection.username">postgres</property>
            <property name="hibernate.connection.password">root</property>
            <property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/provahib</property>
    
            <property name="connection_pool_size">1</property>
    
            <property name="hbm2ddl.auto">create</property>
    
            <property name="show_sql">true</property>
    
            <mapping class="org.massimo.dettagliUser.User" />
            
        </session-factory>
    </hibernate-configuration>
    Invece, tutti gli stessi ma personalizzati settaggi con mysql, funziona.

  2. #2
    Utente di HTML.it L'avatar di andbin
    Registrato dal
    Jan 2006
    residenza
    Italy
    Messaggi
    18,284
    Quote Originariamente inviata da Ironmax Visualizza il messaggio
    INFO: HHH000227: Running hbm2ddl schema export
    Hibernate: drop table if exists User cascade
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: HHH000389: Unsuccessful: drop table if exists User cascade
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: ERRORE: errore di sintassi a o presso "User"
    Posizione: 22
    Hibernate: create table User (userId int4 not null, userName varchar(255), primary key (userId))
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: HHH000389: Unsuccessful: create table User (userId int4 not null, userName varchar(255), primary key (userId))
    ott 14, 2016 7:17:47 PM org.hibernate.tool.hbm2ddl.SchemaExport perform
    ERROR: ERRORE: errore di sintassi a o presso "User"
    Posizione: 14
    La parola user è riservata in SQL. Evita in generale di far generare tabelle/campi con quel nome.


    P.S. vedi anche questa ricerca.
    Ultima modifica di andbin; 14-10-2016 a 20:44
    Andrea, andbin.devSenior Java developerSCJP 5 (91%) • SCWCD 5 (94%)
    java.util.function Interfaces Cheat SheetJava Versions Cheat Sheet

  3. #3
    Utente di HTML.it L'avatar di Ironmax
    Registrato dal
    Dec 2008
    Messaggi
    1,026
    Grazie andbin.
    Ora funziona tutto.
    Ho modificato il nome della classe da "User" a "UtenteUser", ed ha creato una tabella del medesimo nome inserendo i dati relativi.
    User è una parola riservata però il fatto è che con mysql funziona, comunque starò attento ad ometterle dal codice.

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.