File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes java.sql.SQLException: ORA-00942: table or view does not exist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "java.sql.SQLException: ORA-00942: table or view does not exist" Watch "java.sql.SQLException: ORA-00942: table or view does not exist" New topic
Author

java.sql.SQLException: ORA-00942: table or view does not exist

Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Hi Everybody,

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?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Enable hibernate debugging (in hibernate.properties). It should show you if there is a mistake in the mapping, which you just might not have noticed.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
I have enabled the debugging but there is no mapping problem it still throws the above exception. Any idea??
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So you can see the SQL Hibernate is trying to run? And its valid?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
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.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What I mean is have you tried running the generated SQL Hibernate's debug will show you against your DB directly?
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
It actually not generated any sql as you can see the error description is table or view does not exist so it doesn't generated any sql. I think the error occured before that.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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 ]
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
Hi 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.
Ali Gohar
Ranch Hand

Joined: Mar 18, 2004
Posts: 572
I have solved the problem. I have changed that generator to assigned. Thanks very much for your replies.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

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.
Krishna Kuchibhotla
Greenhorn

Joined: Aug 05, 2004
Posts: 1
I am facing the same exact problem as above and my generator is as follows

<id name="id" column="id" type="int">
<generator class="hilo"/>
</id>

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:
srinu varsha
Greenhorn

Joined: Jun 17, 2005
Posts: 2
I got the same problem but am using mysql data base.
net.sf.hibernate.JDBCException: Could not save object

by changing generator class name "hilo " to "assigned" in id tag ..i come out of the problem

<generator class="assigned">
</generator>
Dorival Cardozo
Greenhorn

Joined: Sep 05, 2005
Posts: 1
For MySQL you may use:

<generator class="native"/>

I got success with it !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java.sql.SQLException: ORA-00942: table or view does not exist