I am using Hibernate to save a record in database. I have a bean named Product and i have made the hibernate.properties file and Product.hbm.xml file. But when i run the code it stops with an exception as following:
net.sf.hibernate.JDBCException: Could not save object at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:776) at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:731) at test.poc.com.xavor.wb.TestHibernate.main(TestHibernate.java:31) Caused by: java.sql.SQLException: ORA-00942: table or view does not exist at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:168) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:208) at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:543) at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1405) at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java:643) at oracle.jdbc.driver.OracleStatement.doExecuteQuery(OracleStatement.java:1674) at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1870) at oracle.jdbc.driver.OraclePreparedStatement.executeUpdate(OraclePreparedStatement.java:363) at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:314) at net.sf.hibernate.id.TableGenerator.generate(TableGenerator.java:93) at net.sf.hibernate.id.TableHiLoGenerator.generate(TableHiLoGenerator.java:59) at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:758) ... 2 more Exception in thread "main"
I am using Oracle database. I have varified the table name mentioned in the mapping file Product.hbm.xml with the Database table. Can anybody tell me why this exception is raising?
Yes Hibernate is running. I have used session.find() method and its working fine. But when i try to use save method then it throws the exception. and i am using the same table name as in hbm.xml file as in find method.
The error is an ORA-00942 error i.e. it was thrown by Oracle, so some query must have been run (you can see the "executeQuery" errors further down the stack trace). If you can't see any SQL, then I suspect you have not enabled Hibernate debugging.
However, you seem to be using Hibernate's HiLo PK generation stuff. Which HiLo strategy are you using? If you are going to the DB for a PK from a sequence, make sure the sequence exists. [ May 20, 2004: Message edited by: Paul Sturrock ]
Thanks very much for your replies. How can i enable the debugging? It shows some log4j messages. So thats why i was saying i have enabled the debugging. So please tell me the way to enable the debugging. Secondly i am using the Hilo to genertate the key but i don't want to generate a random key and then store it in the table. I actually want to provide my own key. How can i achieve that. I have tried to skip the <generator> tag from that xml file but the program throws error that generator tag is missing.
So please help me out of this my primary key is int in java class and INTEGER in oracle table. Thanks again for your replies.
posted 15 years ago
I have solved the problem. I have changed that generator to assigned. Thanks very much for your replies.
Good Ali. For future reference, you need to set this property "hibernate.show_sql=true" in hibernate.properties, and set the log4j logging level for hibernate classes to debug (or even trace, if you really want to see everything). Its very, very useful for fixing mapping & invalid HQL issues.
Below is the error message. Please reply as soon as possible
2004-08-05 13:04:17 ERROR JDBCException.<init>(38) - Could not save object java.sql.SQLException: ORA-00942: table or view does not exist at oracle.jdbc.dbaccess.DBError.throwSqlException(DBError.java:134) at oracle.jdbc.ttc7.TTIoer.processError(TTIoer.java:289) at oracle.jdbc.ttc7.Oall7.receive(Oall7.java:579) at oracle.jdbc.ttc7.TTC7Protocol.doOall7(TTC7Protocol.java:1894) at oracle.jdbc.ttc7.TTC7Protocol.parseExecuteDescribe(TTC7Protocol.java: