I searched the forums and I couldn't find anything which quite matched my problem.
I am making my initial pass at integrating Hibernate. This code is more of a demo, trying to do a proof of concept.
The following code is generating a null pointer when I try to open a session connecting to an Oracle 10g DB and Hibernate 2.1.
public class EditApplications
{
public EditApplications(){}
private static SessionFactory sessionFactory;
static
{
try
{
Configuration cfg = new Configuration();
cfg.setProperties(System.getProperties());
//sessionFactory = cfg.buildSessionFactory();
sessionFactory = cfg.configure().buildSessionFactory();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static Session getSession() throws HibernateException
{
>>>>>This is the line which throws the exception
return sessionFactory.openSession();
}
public boolean updateAppName(Integer appId, String newAppName)
{
Session session = null;
Transaction transaction = null;
try
{
//Set up the hibernate session
session = getSession();
transaction = session.beginTransaction();
//get the record to edit
Applications app = (Applications)session.load(Applications.class, appId);
//Pass the new values to update for this record
app.setAppName(newAppName);
//complete the hibernate transaction and commit the changes
transaction.commit();
return true;
}
catch (HibernateException hex)
{
hex.printStackTrace();
try
{
transaction.rollback();
session.close();
}
catch (HibernateException e)
{
e.printStackTrace();
}
return false;
}
}
}
hibernate.cfg.xml -
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
<property name="connection.url">jdbc:oracle:thin:@localhost:1521:DEV04</property>
<property name="connection.username">xxxxxx</property>
<property name="connection.password">xxxxxx</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.Oracle9Dialect</property>
<property name="transaction.factory_class">
net.sf.hibernate.transaction.JDBCTransactionFactory
</property>
<mapping resource="com/xxxxxx/model/AppActiveSession.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppAppUserRoles.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppAuditCategory.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppAuditEvent.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppActiveSession.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppDmis.hbm.xml"/>
<mapping resource="com/xxxxxx/model/ApplicationRoles.hbm.xml"/>
<mapping resource="com/xxxxxx/model/Applications.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppRoles.hbm.xml"/>
<mapping resource="com/xxxxxx/model/AppUser.hbm.xml"/>
<mapping resource="com/xxxxxx/model/passwordhistory.hbm.xml"/>
<mapping resource="com/xxxxxx/model/UserAccountActivity.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Last edited by psuross on Mon Nov 13, 2006 12:36 pm, edited 2 times in total.
|