-->
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.  [ 1 post ] 
Author Message
 Post subject: Null Pointer Exception :( :(
PostPosted: Sun Dec 27, 2009 4:22 pm 
Newbie

Joined: Sun Dec 27, 2009 4:52 am
Posts: 4
Hi all,

Im getting the following null pointer exception when i try to persist an object using Hibernate.
Im using Spring's hibernate templates for this.

below i have posted the stack trace i got and i have posted the source files and the mapping file.

Its a big help if anyone could provide an answer.

Thanks in advance
saj

Code:
Exception in thread "main" java.lang.NullPointerException
   at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:649)
   at com.mysql.jdbc.PreparedStatement.asSql(PreparedStatement.java:587)
   at com.mysql.jdbc.PreparedStatement.toString(PreparedStatement.java:4068)
   at java.lang.String.valueOf(Unknown Source)
   at java.lang.StringBuffer.append(Unknown Source)
   at com.mysql.jdbc.trace.Tracer.printParameters(Tracer.aj:240)
   at com.mysql.jdbc.trace.Tracer.printEntering(Tracer.aj:167)
   at com.mysql.jdbc.trace.Tracer.entry(Tracer.aj:126)
   at com.mysql.jdbc.trace.Tracer.ajc$before$com_mysql_jdbc_trace_Tracer$1$f51c62b8(Tracer.aj:45)
   at com.mysql.jdbc.Connection.registerStatement(Connection.java)
   at com.mysql.jdbc.Statement.<init>(Statement.java:270)
   at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:500)
   at com.mysql.jdbc.Connection.clientPrepareStatement(Connection.java:2187)
   at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4829)
   at com.mysql.jdbc.Connection.prepareStatement(Connection.java:4734)
   at org.apache.commons.dbcp.DelegatingConnection.prepareStatement(DelegatingConnection.java:248)
   at org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper.prepareStatement(PoolingDataSource.java:302)
   at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:116)
   at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:109)
   at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:244)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2382)
   at org.hibernate.persister.entity.AbstractEntityPersister.updateOrInsert(AbstractEntityPersister.java:2335)
   at org.hibernate.persister.entity.AbstractEntityPersister.update(AbstractEntityPersister.java:2635)
   at org.hibernate.action.EntityUpdateAction.execute(EntityUpdateAction.java:115)
   at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:279)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:263)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:168)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:50)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1027)
   at org.springframework.orm.hibernate3.HibernateAccessor.flushIfNecessary(HibernateAccessor.java:390)
   at org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:420)
   at org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   at org.springframework.orm.hibernate3.HibernateTemplate.saveOrUpdate(HibernateTemplate.java:748)
   at com.shopatme.dao.abstractdao.BaseDAOImpl.create(BaseDAOImpl.java:25)
   at com.shopatme.dao.userdao.UserDAOImpl.create(UserDAOImpl.java:26)
   at com.shopatme.dao.userdao.UserDAOImpl.create(UserDAOImpl.java:1)
   at com.shopatme.dao.abstractdao.BaseDAOImpl.create(BaseDAOImpl.java:1)
   at com.shopatme.TestClass.main(TestClass.java:25)



Code:
public class BaseDAOImpl<T extends Entity> extends HibernateDaoSupport implements BaseDAO<T> {

   public BaseDAOImpl() {

   }

   @Override
   public void create(T t) {

      getHibernateTemplate().saveOrUpdate(t);
      

   }

   @Override
   public void delete(T t) {

      getHibernateTemplate().delete(t);
   }

   @Override
   public void update(T t) {
      getHibernateTemplate().update(t);

   }

   @Override
   public List<T> findAll(Class<T> t) {

      return getHibernateTemplate().find("from" + t.getName());
   }

}


Code:
public class UserDAOImpl extends BaseDAOImpl<User> implements UserDAO{

   @Override
   public User find() {
      
      return null;
   }

   @Override
   public void create(User t) {
      
      super.create(t);
   }

   @Override
   public void delete(User t) {
      super.delete(t);
   }

   @Override
   public List<User> findAll(Class<User> t) {
      return super.findAll(t);
   }

   @Override
   public void update(User t) {
      super.update(t);
   }
}


Code:


public class User extends Entity{

   /**
    *
    */
   private static final long serialVersionUID = 2345571475794359466L;

   private String userName;
   
   private String password;
   
   private String firstName;
   
   private String lastName;
   
   private String department;

   public String getUserName() {
      return userName;
   }

   public void setUserName(String userName) {
      this.userName = userName;
   }

   public String getPassword() {
      return password;
   }

   public void setPassword(String password) {
      this.password = password;
   }

   public String getFirstName() {
      return firstName;
   }

   public void setFirstName(String firstName) {
      this.firstName = firstName;
   }

   public String getLastName() {
      return lastName;
   }

   public void setLastName(String lastName) {
      this.lastName = lastName;
   }

   public String getDepartment() {
      return department;
   }

   public void setDepartment(String department) {
      this.department = department;
   }
}



Code:
<hibernate-mapping>
   <class name="com.shopatme.common.domainobjects.User"
      table="user_login">
      <id name="id" type="long" column="id">
         <generator class="native" />
      </id>
      <property name="userName" type="string" column="username"/>
      <property name="password" type="string" column="password"/>
      
      <join table="user_details">
         <key column="" />
         <property name="firstName" type="string" column="first_name"/>
         <property name="lastName" type="string" column="last_name"/>
         <property name="department" type="string" column="department"/>
      </join>
      
   </class>
</hibernate-mapping>


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

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.