-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Nullpointer on SessionFactory openSession
PostPosted: Mon Nov 13, 2006 11:57 am 
Newbie

Joined: Mon Nov 13, 2006 11:49 am
Posts: 6
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.

Top
 Profile  
 
 Post subject: Stacktrace
PostPosted: Mon Nov 13, 2006 12:02 pm 
Newbie

Joined: Mon Nov 13, 2006 11:49 am
Posts: 6
java.lang.NullPointerException
com.xxxxx.appsadmin.stuff.EditApplications.updateAppName(EditApplications.java:50)
com.xxxxxs.appsadmin.servlet.UpdateApplicationsServlet.doGet(UpdateApplicationsServlet.java:41)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.