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 );
}
}
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 );
}
}