hibernate question

D

Daniel

Hi all,

Hope you guys don't mind one more question for today. I am working with
Oracle 9 database with Hibernate.

I have a class called User that is mapped to the table UserList. The
queries to retrieve the data run fine, but every time I try to save
(insert) information into UserList, I get the following error:

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

So, how did I get the query results back? Below are the hbm config file
for User, and the save and getUsers methods.

PS. In the mapping file, for table, I tried "userlist" and
"system.userlist" - same results. And I made sure to use the proper
dialect (Oracle9Dialect).

Thanks in advance!



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="bean.User" table="system.userlist">

<id name="id"
column="id">
<generator class="increment"/>
</id>

<property name="username" column="username"/>
<property name="password" column="password"/>
<property name="firstname" column="firstname"/>
<property name="lastname" column="lastname"/>
<property name="phone" column="phone"/>
<property name="email" column="email"/>
<property name="state" column="state"/>


</class>
</hibernate-mapping>

The two methods:

// This runs fine, no problems.
public List<User> getUsers()
{
try
{
Session session = getSession();

Query query = session.createQuery( "from User" );

List list = query.list();

return list;
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
finally
{
closeSession();
}
}


// This does not run - give me the exception error
public void save( User user )
{
try
{
Session session = getSession();

System.out.println( "UserEntity.save()" );

session.save( user );
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
finally
{
closeSession();
}
}



Additional info:

public Session getSession()
{
try
{
if ( sessionFactory == null )
{
init();
}
session = sessionFactory.openSession();

transaction = session.beginTransaction();

return session;
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
}

public void closeSession()
{
try
{
if ( transaction != null )
{
transaction.commit();
}
if ( session != null && session.isOpen() )
{
session.close();
}
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
}
 
C

Chris Smith

Daniel said:
I have a class called User that is mapped to the table UserList. The
queries to retrieve the data run fine, but every time I try to save
(insert) information into UserList, I get the following error:

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

Wow, that's a really non-specific error message that Oracle is giving
out. You'll need to find out what SQL Hibernate is issuing to cause
that error. The hibernate.show_sql config option is the easiest way to
do this.

--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
T

Tony Morris

Daniel said:
Hi all,

Hope you guys don't mind one more question for today. I am working with
Oracle 9 database with Hibernate.

I have a class called User that is mapped to the table UserList. The
queries to retrieve the data run fine, but every time I try to save
(insert) information into UserList, I get the following error:

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

So, how did I get the query results back? Below are the hbm config file
for User, and the save and getUsers methods.

PS. In the mapping file, for table, I tried "userlist" and
"system.userlist" - same results. And I made sure to use the proper
dialect (Oracle9Dialect).

Thanks in advance!



<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping>

<class name="bean.User" table="system.userlist">

<id name="id"
column="id">
<generator class="increment"/>
</id>

<property name="username" column="username"/>
<property name="password" column="password"/>
<property name="firstname" column="firstname"/>
<property name="lastname" column="lastname"/>
<property name="phone" column="phone"/>
<property name="email" column="email"/>
<property name="state" column="state"/>


</class>
</hibernate-mapping>

The two methods:

// This runs fine, no problems.
public List<User> getUsers()
{
try
{
Session session = getSession();

Query query = session.createQuery( "from User" );

List list = query.list();

return list;
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
finally
{
closeSession();
}
}


// This does not run - give me the exception error
public void save( User user )
{
try
{
Session session = getSession();

System.out.println( "UserEntity.save()" );

session.save( user );
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
finally
{
closeSession();
}
}



Additional info:

public Session getSession()
{
try
{
if ( sessionFactory == null )
{
init();
}
session = sessionFactory.openSession();

transaction = session.beginTransaction();

return session;
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
}

public void closeSession()
{
try
{
if ( transaction != null )
{
transaction.commit();
}
if ( session != null && session.isOpen() )
{
session.close();
}
}
catch( Exception ex )
{
throw new RuntimeException( ex );
}
}

Turn on Hibernate SQL tracing and us what it's doing.
 
D

Daniel

I have the following property set in hibernate.cfg.xml:
<property name="show_sql">true</property>

It shows me the sql for the successful query *after* it has completed.
So, when I try to see it for the insert (the one I am having problems
with), there is no sql printout because it bugs out before it can
complete.

Any thoughts?

Thanks.
 
T

Tony Morris

Daniel said:
I have the following property set in hibernate.cfg.xml:
<property name="show_sql">true</property>

It shows me the sql for the successful query *after* it has completed.
So, when I try to see it for the insert (the one I am having problems
with), there is no sql printout because it bugs out before it can
complete.

Any thoughts?

Thanks.

There is a JDBC driver out there somewhere (sorry, I forget the name) that
acts as a proxy to the real driver.
There you can watch the SQL being submitted to the driver.
Once you have that SQL, you can isolate a test case away from Hibernate (and
I assume, your application server).
From there, a resolution is relatively simple.

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,059
Latest member
cryptoseoagencies

Latest Threads

Top