Traditional Hibernate Issues (POJO): Part#2 ERROR: No database selected

Having problems with the database configuration and XML mapping configurations.

 Oct 29, 2016 2:02:36 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections
 INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
 Oct 29, 2016 2:02:36 PM org.hibernate.dialect.Dialect
 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
 Hibernate: /* insert com.navid.practice.hibernate.User */ insert into USERS (NAME, TOTAL, ID) values (?, ?, ?)
 Oct 29, 2016 2:02:36 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 WARN: SQL Error: 1046, SQLState: 3D000
 Oct 29, 2016 2:02:36 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 ERROR: No database selected
 Oct 29, 2016 2:02:36 PM org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl release
 INFO: HHH000010: On release of batch it still contained JDBC statements
 Oct 29, 2016 2:02:36 PM org.hibernate.internal.ExceptionMapperStandardImpl mapManagedFlushFailure
 ERROR: HHH000346: Error during managed flush [org.hibernate.exception.GenericJDBCException: could not execute statement]
 javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute statement
 at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:147)
 at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
 at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
 at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1412)
 at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:476)
 at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3165)
 at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2379)
 at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:467)
 at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
 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:220)
 at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:68)
 at com.navid.practice.hibernate.Program.main(Program.java:26)
 Caused by: org.hibernate.exception.GenericJDBCException: could not execute statement
 at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
 at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
 at org.hibernate.engine
 

the issue was resolved by changing the highelighed part to the proper part according to the database configuration.

<hibernate-mapping>
    <class name="com.navid.practice.hibernate.User" table="USERS">
        <id name="id" type="int">
            <column name="ID" />
            <generator class="assigned" />
        </id>
        <property name="name" type="java.lang.String">
            <column name="NAME" />
        </property>
        <property name="total" type="int">
            <column name="TOTAL" />
        </property>
    </class>
</hibernate-mapping>

 

Solution:

in database side, that table’s field = ID, was configuration as auto increment so I change that highlighted line to identity.

<generator class="identity" />

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s