Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Hibernate Stoped Working

mysqli hibernate

  • Please log in to reply
4 replies to this topic

#1 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 15 July 2012 - 11:14 AM

So I had hibernate setup a project I was working on and I had confirmed that I was able to save and query for entity objects. However today I get this exception:

Hibernate: select this_.USER_ID as USER1_0_0_, this_.BIRTHDATE as BIRTHDATE0_0_, this_.EMAIL as EMAIL0_0_, this_.FIRST_NAME as FIRST4_0_0_, this_.GENDER as GENDER0_0_, this_.LAST_NAME as LAST6_0_0_, this_.PASSWORD as PASSWORD0_0_ from MOBSTER_USER this_ where this_.EMAIL=?
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Table 'mobsterdb.MOBSTER_USER' doesn't exist
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
at $Proxy17.executeQuery(Unknown Source)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:829)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
at org.hibernate.loader.Loader.doList(Loader.java:2438)
at org.hibernate.loader.Loader.doList(Loader.java:2424)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2254)
at org.hibernate.loader.Loader.list(Loader.java:2249)
at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:122)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1622)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
at mobster.persistence.dao.MobsterUserDAO.createUser(MobsterUserDAO.java:34)
at cc.main(cc.java:17)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'mobsterdb.MOBSTER_USER' doesn't exist
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
at com.mysql.jdbc.Util.getInstance(Util.java:386)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1053)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4074)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4006)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2468)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2629)
at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2719)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2318)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
... 14 more


Now that exception seems to say that I'm querying a non existant table, but I assure you that I'm not. Here you can see the data explorer that shows my db and the tables and the columns. You'll see that it clearly exists.

Any suggestions?
  • 0

#2 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 15 July 2012 - 03:11 PM

I figured it out. When I synced my database model the last time. I evidently messed up the schema in the db.
  • 0

#3 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 15 July 2012 - 05:14 PM

Ok I lied it's not fixed. I wrote a little program that hit's the db here's the source for that:
public static void main(String[] args) throws ExistingUserException {
//SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE();
EntityManagerFactory factory = Persistence.createEntityManagerFactory("mobsterdb");
HibernateEntityManager manager = (HibernateEntityManager) factory.createEntityManager();
@SuppressWarnings("unchecked")
List<String> tables = manager.getSession().createSQLQuery("SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE();").list();
System.out.println(tables);
MobsterUserDAO userDAO = new MobsterUserDAO();
LastFmAccountDAO lastFmDAO = new LastFmAccountDAO();
MobsterUser john = new MobsterUser("test@testy.com", "password", "John", "test", 'm', new Date(0));
LastFmAccount johnsAccount = new LastFmAccount("test", "password", john);
userDAO.createUser(john);
System.out.println(john);
lastFmDAO.create(johnsAccount);
System.out.println(johnsAccount);
}

Ok what this does is query the db for all the table names. Then it creates a user and persists him and prints him on the console. Once that has completed we associate him w/ a last.fm account and print that account on the console. Here's the console output for the program.

Hibernate: SELECT TABLE_NAME FROM information_schema.TABLES WHERE TABLE_SCHEMA=DATABASE();
[LAST_FM_ACCOUNT, LISTENING_DATA, Last_Fm_Tag, Mobster_Album, Mobster_Artist, Mobster_Song]
Hibernate: select this_.USER_ID as USER1_4_0_, this_.BIRTHDATE as BIRTHDATE4_0_, this_.EMAIL as EMAIL4_0_, this_.FIRST_NAME as FIRST4_4_0_, this_.GENDER as GENDER4_0_, this_.LAST_NAME as LAST6_4_0_, this_.PASSWORD as PASSWORD4_0_ from MOBSTER_USER this_ where this_.EMAIL=?
Exception in thread "main" org.hibernate.exception.SQLGrammarException: Table 'mobsterdb.MOBSTER_USER' doesn't exist
at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:82)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
......... same as above


As you can see the table it's complaining about is obviously there. However It cant seem to find it when I make queries.

Maybey I should just learn to read. The table is definitely not listed.
  • 0

#4 wim DC

wim DC

    Roar

  • Expert Member
  • PipPipPipPipPipPipPipPip
  • 2681 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Python

Posted 15 July 2012 - 10:53 PM

Well, some classical questions:

Is MOBSTER_USER class annotated properly?

AND is it listed in persistence.xml or otherwise found trough package scanning?

Or maybe you used mapping files, in which case the hbm.xml file should be listed in hibernate.cfg.xml
  • 0

#5 mctim

mctim

    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 110 posts

Posted 17 July 2012 - 10:27 PM

I don't know if you saw my last comment "maybe I should learn to read." I had somehow managed to delete that table from the db but I update the schema and fixed the issue It's fixed now.
  • 0





Also tagged with one or more of these keywords: mysqli, hibernate

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download