Traditional Hibernate Issues (POJO): Part#3 : can’t find the database:

can’t find the database:

INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
 Oct 29, 2016 2:05:15 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) values (?, ?)
 Oct 29, 2016 2:05:15 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 WARN: SQL Error: 1046, SQLState: 3D000
 Oct 29, 2016 2:05:15 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 ERROR: No database selected
 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.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
 at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2840)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3411)
 at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
 at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:623)
 at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:277)
 at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:258)
 at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:303)
 at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
 at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
 at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
 at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
 at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
 at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
 at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:674)
 at org.hibernate.internal.SessionImpl.save(SessionImpl.java:666)
 at org.hibernate.internal.SessionImpl.save(SessionImpl.java:661)
 at com.navid.practice.hibernate.Program.main(Program.java:23)
 Caused by: java.sql.SQLException: No database selected
 at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3970)
 at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3906)
 at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2524)
 at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2677)
 at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2549)
 at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
 at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
 at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
 at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5098)
 at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
 at org.hibernate.engine.jdb

Solution:

check the configuration xml file and you have to make sure, the database is mentioned in the url.

jdbc:mysql://localhost:3306/

Mine didn’t have that, so I added.

jdbc:mysql://localhost:3306/MyPersonalDatabaseName
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