The generated SQL code is putting underscores in the query which causes a table not found exception. I've put my mapping info below. I searched the forum and found similar problems from other users, but I didn't see a clear way to fix it. I don't have a schema name specified anywhere.
Any ideas on how to get these underscores out? The mapping would work if it wasn't for them.
Hibernate version: 3.0.5
Hibernate config excerpt:
<property name="show_sql">true</property>
<property name="hibernate.connection.driver_class">org.gjt.mm.mysql.Driver</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
Mapping documents:
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="edu.uiuc.cs411.rentalproperty.domain.Managers" table="managers" catalog="cs411">
<id name="contactId" type="integer">
<column name="contact_id" />
<generator class="assigned" />
</id>
<property name="username" type="string">
<column name="username" length="8" />
</property>
<property name="password" type="string">
<column name="password_" length="10" />
</property>
<set name="propertieses" inverse="true">
<key>
<column name="manager_id" not-null="true" />
</key>
<one-to-many class="edu.uiuc.cs411.rentalproperty.domain.Properties" />
</set>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
Transaction aTransaction = aSession.beginTransaction();
Managers manager = new Managers();
manager.setUsername("test");
manager.setPassword("test");
manager.setContactId(new Integer(1));
aSession.save(manager);
aTransaction.commit();
Full stack trace of any exception that occurs:
2005-07-04 16:26:42,796 [http-8080-Processor25] DEBUG - insert into cs411__managers (username, password_, contact_id) values (?, ?, ?)
2005-07-04 16:26:42,796 [http-8080-Processor25] DEBUG - preparing statement
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - Dehydrating entity: [edu.uiuc.cs411.rentalproperty.domain.Managers#1]
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - binding 'test' to parameter: 1
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - binding 'test' to parameter: 2
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - binding '1' to parameter: 3
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - Adding to batch
2005-07-04 16:26:42,859 [http-8080-Processor25] DEBUG - Executing batch size: 1
2005-07-04 16:26:42,875 [http-8080-Processor25] DEBUG - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2005-07-04 16:26:42,875 [http-8080-Processor25] DEBUG - closing statement
2005-07-04 16:26:42,875 [http-8080-Processor25] DEBUG - Could not execute JDBC batch update [insert into cs411__managers (username, password_, contact_id) values (?, ?, ?)]
java.sql.BatchUpdateException: Table 'cs411.cs411__managers' doesn't exist
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:891)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at edu.uiuc.cs411.rentalproperty.struts.action.TestHibernateAction.execute(TestHibernateAction.java:37)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
2005-07-04 16:26:42,890 [http-8080-Processor25] WARN - SQL Error: 1146, SQLState: 42S02
2005-07-04 16:26:42,890 [http-8080-Processor25] ERROR - Table 'cs411.cs411__managers' doesn't exist
2005-07-04 16:26:42,890 [http-8080-Processor25] ERROR - Could not synchronize database state with session
org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:161)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:293)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86)
at edu.uiuc.cs411.rentalproperty.struts.action.TestHibernateAction.execute(TestHibernateAction.java:37)
at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
at java.lang.Thread.run(Thread.java:595)
Caused by: java.sql.BatchUpdateException: Table 'cs411.cs411__managers' doesn't exist
at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:891)
at org.apache.tomcat.dbcp.dbcp.DelegatingStatement.executeBatch(DelegatingStatement.java:294)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:154)
... 28 more
Name and version of the database you are using:
MySQL 4.1
The generated SQL (show_sql=true):
insert into cs411__managers (username, password_, contact_id) values (?, ?, ?)
Debug level Hibernate log excerpt:
shown above
|