Please help. I have been stuck with it for a while now.
java.lang.NullPointerException
at org.hibernate.tuple.entity.AbstractEntityTuplizer. getPropertyValue(AbstractEntityTuplizer.java:521)
I have search a lot on this but couldn't find any solution. Below is my method and servlet mappings
Code:
public void saveNewUser(UserDTO userDTO){
try{
Session session =getSessionFactory().getCurrentSession();
session.save(userDTO);
}catch(HibernateException ex){
throw new HibernateException(ex);
}
}
Code:
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<beans:property name="sessionFactory" ref="sessionFactory" />
</beans:bean>
<beans:bean id="userTransactionProxy"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<beans:property name="transactionManager" ref="transactionManager" />
<beans:property name="transactionAttributes">
<beans:props>
<beans:prop key="*">PROPAGATION_REQUIRED</beans:prop>
</beans:props>
</beans:property>
<beans:property name="target">
<beans:ref bean="userDAO" />
</beans:property>
</beans:bean>
Code:
Hibernate: select userdto0_.UserId as UserId0_, userdto0_.UserName as UserName0_, userdto0_.UserSchoolId as UserScho3_0_, userdto0_.UserPassword as UserPass4_0_, userdto0_.UserRole as UserRole0_, userdto0_.UserStatus as UserStatus0_ from users.User userdto0_ where username=?
Hibernate: select userperson0_.UserPersonalInfoId as UserPers1_5_0_, userperson0_.UserFirstName as UserFirs2_5_0_, userperson0_.UserLastName as UserLast3_5_0_, userperson0_.UserEmail as UserEmail5_0_, userperson0_.UserContactNumber as UserCont5_5_0_, userperson0_.UserAddress as UserAddr6_5_0_ from users.UserPersonalInfo userperson0_ where userperson0_.UserPersonalInfoId=?
Hibernate: select userdto0_.UserId as UserId0_, userdto0_.UserName as UserName0_, userdto0_.UserSchoolId as UserScho3_0_, userdto0_.UserPassword as UserPass4_0_, userdto0_.UserRole as UserRole0_, userdto0_.UserStatus as UserStatus0_ from users.User userdto0_ where username=?
Hibernate: select userperson0_.UserPersonalInfoId as UserPers1_5_0_, userperson0_.UserFirstName as UserFirs2_5_0_, userperson0_.UserLastName as UserLast3_5_0_, userperson0_.UserEmail as UserEmail5_0_, userperson0_.UserContactNumber as UserCont5_5_0_, userperson0_.UserAddress as UserAddr6_5_0_ from users.UserPersonalInfo userperson0_ where userperson0_.UserPersonalInfoId=?
Hibernate: select userdto0_.UserId as UserId0_, userdto0_.UserName as UserName0_, userdto0_.UserSchoolId as UserScho3_0_, userdto0_.UserPassword as UserPass4_0_, userdto0_.UserRole as UserRole0_, userdto0_.UserStatus as UserStatus0_ from users.User userdto0_ where username=?
Hibernate: insert into users.User (UserName, UserSchoolId, UserPassword, UserRole, UserStatus, UserId) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into users.UserPersonalInfo (UserFirstName, UserLastName, UserEmail, UserContactNumber, UserAddress, UserPersonalInfoId) values (?, ?, ?, ?, ?, ?)
Mar 16, 2012 12:44:30 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [blackboard] in context with path [/Blackboard] threw exception [Request processing failed; nested exception is java.lang.Exception: java.lang.NullPointerException] with root cause
java.lang.NullPointerException
at org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:521)
at org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3867)
at org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:100)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
at org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)
at com.peanuts.blackboard.database.dao.impl.StudentDAO.savenewStudent(StudentDAO.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
at
w is stack trace from browser
Code:
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.Exception: java.lang.NullPointerException
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:656)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.Exception: java.lang.NullPointerException
com.peanuts.blackboard.web.controller.admin.AdminAddUserController.onSubmit(AdminAddUserController.java:89)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:176)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:426)
org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:414)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:790)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:719)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:644)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:560)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.NullPointerException
org.hibernate.tuple.entity.AbstractEntityTuplizer.getPropertyValue(AbstractEntityTuplizer.java:521)
org.hibernate.persister.entity.AbstractEntityPersister.getPropertyValue(AbstractEntityPersister.java:3867)
org.hibernate.id.ForeignGenerator.generate(ForeignGenerator.java:100)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:210)
org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:56)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:195)
org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:50)
org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:93)
org.hibernate.impl.SessionImpl.fireSave(SessionImpl.java:713)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:701)
org.hibernate.impl.SessionImpl.save(SessionImpl.java:697)
com.peanuts.blackboard.database.dao.impl.StudentDAO.savenewStudent(StudentDAO.java:72)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:597)
org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:309)
org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
mapping
Code:
<hibernate-mapping>
<class name="com.peanuts.blackboard.database.dto.UserDTO" table="users.User">
<id column="UserId" name="userId" type="java.lang.Integer">
<generator class="org.hibernate.id.TableHiLoGenerator">
<param name="table">Identity</param>
<param name="column">NEXT</param>
</generator>
</id>
<one-to-one name="userPersonalInfoDTO" class="com.peanuts.blackboard.database.dto.UserPersonalInfoDTO" cascade="save-update"/>
<property column="UserName" name="userName" type="java.lang.String"/>
<property column="UserSchoolId" name="userSchoolId" type="java.lang.Integer"/>
<property column="UserPassword" name="userPassword" type="java.lang.String"/>
<property column="UserRole" name="userRole" type="java.lang.String"/>
<property column="UserStatus" name="userStatus" type="java.lang.String"/>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="com.peanuts.blackboard.database.dto.UserPersonalInfoDTO" table="users.UserPersonalInfo">
<id column="UserPersonalInfoId" name="userPersonalInfoId" type="java.lang.Integer">
<generator class="org.hibernate.id.ForeignGenerator">
<param name="property">userDTO</param>
<param name="column">NEXT</param>
</generator>
</id>
<one-to-one name="userDTO" class="com.peanuts.blackboard.database.dto.UserDTO" constrained="true"/>
<property column="UserFirstName" name="userFirstName" type="java.lang.String"/>
<property column="UserLastName" name="userLastName" type="java.lang.String"/>
<property column="UserEmail" name="userEmail" type="java.lang.String"/>
<property column="UserContactNumber" name="userContactNumber" type="java.lang.String"/>
<property column="UserAddress" name="userAddress" type="java.lang.String"/>
</class>
</hibernate-mapping>
userDTO
Code:
public class UserDTO {
private int userId;
private String userName;
private int userSchoolId;
private String userPassword;
private String userRole;
private String userStatus;
private UserPersonalInfoDTO userPersonalInfoDTO;
public int getUserId() {
return userId;
}
public void setUserId(int userId) {
this.userId = userId;
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public int getUserSchoolId() {
return userSchoolId;
}
public void setUserSchoolId(int userSchoolId) {
this.userSchoolId = userSchoolId;
}
public String getUserPassword() {
return userPassword;
}
public void setUserPassword(String userPassword) {
this.userPassword = userPassword;
}
public String getUserRole() {
return userRole;
}
public void setUserRole(String userRole) {
this.userRole = userRole;
}
public String getUserStatus() {
return userStatus;
}
public void setUserStatus(String userStatus) {
this.userStatus = userStatus;
}
public UserPersonalInfoDTO getUserPersonalInfoDTO() {
return userPersonalInfoDTO;
}
public void setUserPersonalInfoDTO(UserPersonalInfoDTO userPersonalInfoDTO) {
this.userPersonalInfoDTO = userPersonalInfoDTO;
}
}
UserPErsonalInfoDTO
Code:
public class UserPersonalInfoDTO {
private int userPersonalInfoId;
private String userFirstName;
private String userLastName;
private String userEmail;
private String userContactNumber;
private String userAddress;
private UserDTO userDTO;
public int getUserPersonalInfoId() {
return userPersonalInfoId;
}
public void setUserPersonalInfoId(int userPersonalInfoId) {
this.userPersonalInfoId = userPersonalInfoId;
}
public String getUserFirstName() {
return userFirstName;
}
public void setUserFirstName(String userFirstName) {
this.userFirstName = userFirstName;
}
public String getUserLastName() {
return userLastName;
}
public void setUserLastName(String userLastName) {
this.userLastName = userLastName;
}
public String getUserEmail() {
return userEmail;
}
public void setUserEmail(String userEmail) {
this.userEmail = userEmail;
}
public String getUserContactNumber() {
return userContactNumber;
}
public void setUserContactNumber(String userContactNumber) {
this.userContactNumber = userContactNumber;
}
public String getUserAddress() {
return userAddress;
}
public void setUserAddress(String userAddress) {
this.userAddress = userAddress;
}
public UserDTO getUserDTO() {
return userDTO;
}
public void setUserDTO(UserDTO userDTO) {
this.userDTO = userDTO;
}
}
The results are being saved in database but after that it throws exception.