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: Getting null exception during delete cascade
PostPosted: Tue Nov 23, 2010 11:56 pm 
Newbie

Joined: Thu Jun 10, 2010 7:26 pm
Posts: 2
Hi

I have two objects. Offering is parent while OfferingMessage is child. Offering has a list of OfferingMessages. Following is how I am defining my Offering and OfferingMessage classes.

Offering Class
Code:
package com.shahkaar.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.PolymorphismType;

import com.shahkaar.common.DomainObject;

@Entity
@org.hibernate.annotations.Entity(
        selectBeforeUpdate = true,
        dynamicInsert = true, dynamicUpdate = true,
        optimisticLock = OptimisticLockType.ALL,
        polymorphism = PolymorphismType.EXPLICIT)
@Table(name = "OFFERINGS")
public class Offering extends DomainObject{

   @NotNull
   @Column(name = "VENDORID")
   private String vendorID;

   @NotNull
   @Column(name = "DESCRIPTION")
   private String description;

   @NotNull
   @Column(name = "IMAGEPATH")
   private String imagePath;
   
   @NotNull
   @Column(name = "CATEGORYID")
   private int categoryID;

      
   @OneToMany(cascade={CascadeType.ALL},targetEntity=OfferingMessage.class,fetch=FetchType.EAGER,orphanRemoval=true)
   @JoinColumns({
   @JoinColumn(name="offeringId", referencedColumnName="id")})
   @Fetch(FetchMode.SUBSELECT)
   private List<OfferingMessage> oferMessage = new ArrayList<OfferingMessage>();

   public List<OfferingMessage> getOferMessage() {
      return oferMessage;
   }

   public void setOferMessage(List<OfferingMessage> oferMessage) {
      this.oferMessage = oferMessage;
   }
   
   public String getVendorID() {
      return vendorID;
   }

   public void setVendorID(String vendorID) {
      this.vendorID = vendorID;
   }

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }

   public String getImagePath() {
      return imagePath;
   }

   public void setImagePath(String imagePath) {
      this.imagePath = imagePath;
   }

   public int getCategoryID() {
      return categoryID;
   }

   public void setCategoryID(int categoryID) {
      this.categoryID = categoryID;
   }
}

OfferingMessage Class
Code:
package com.shahkaar.domain;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.OptimisticLockType;
import org.hibernate.annotations.PolymorphismType;

import com.shahkaar.common.DomainObject;

@Entity
@org.hibernate.annotations.Entity(
        selectBeforeUpdate = true,
        dynamicInsert = true, dynamicUpdate = true,
        optimisticLock = OptimisticLockType.ALL,
        polymorphism = PolymorphismType.EXPLICIT)
@Table(name = "OFFERINGMESSAGES")
public class OfferingMessage extends DomainObject{

   @NotNull
   @Column(name = "OFFERINGID")
   private int offeringId;
   
   @NotNull
   @Column(name = "VENDORID")
   private String vendorID;

   @NotNull
   @Column(name = "MESSAGEDESCRIPTION")
   private String msg;

   public String getVendorID() {
      return vendorID;
   }

   public void setVendorID(String vendorID) {
      this.vendorID = vendorID;
   }

   public int getOfferingId() {
      return offeringId;
   }

   public void setOfferingId(int offeringId) {
      this.offeringId = offeringId;
   }

   public String getMsg() {
      return msg;
   }

   public void setMsg(String msg) {
      this.msg = msg;
   }
}



Issue that I am having here is that when I try to delete Offering object I get a null exception.

Following is the code that I am using for delete (in my DAO).
Code:
public DomainObject deleteOffering(Offering offering) {
      
      if (offering == null) {
         return null;
      }
      
      Offering p = (Offering)getSession().load(Offering.class, offering.getId());
      getSession().delete(p);
      getSession().flush();
      return p;
   }


Please advice what I am missing here.
Thanks in advance for helping me.

I am getting following Exception
Code:
21:45:51,771 INFO  FindOfferingsService:34 - No value passed to FindOfferingsService call. This may return huge amount of data.
21:45:51,771 DEBUG SQL:111 - select this_.id as id6_0_, this_.CREATEDTIMESTAMP as CREATEDT2_6_0_, this_.CREATEDUSERID as CREATEDU3_6_0_, this_.MODIFIEDTIMESTAMP as MODIFIED4_6_0_, this_.MODIFIEDUSERID as MODIFIED5_6_0_, this_.CATEGORYID as CATEGORYID6_0_, this_.DESCRIPTION as DESCRIPT7_6_0_, this_.IMAGEPATH as IMAGEPATH6_0_, this_.VENDORID as VENDORID6_0_ from OFFERINGS this_ order by this_.DESCRIPTION asc
21:45:51,771 DEBUG SQL:111 - select ofermessag0_.offeringId as offeringId6_1_, ofermessag0_.id as id1_, ofermessag0_.id as id7_0_, ofermessag0_.CREATEDTIMESTAMP as CREATEDT2_7_0_, ofermessag0_.CREATEDUSERID as CREATEDU3_7_0_, ofermessag0_.MODIFIEDTIMESTAMP as MODIFIED4_7_0_, ofermessag0_.MODIFIEDUSERID as MODIFIED5_7_0_, ofermessag0_.MESSAGEDESCRIPTION as MESSAGED6_7_0_, ofermessag0_.OFFERINGID as OFFERINGID7_0_, ofermessag0_.VENDORID as VENDORID7_0_ from OFFERINGMESSAGES ofermessag0_ where ofermessag0_.offeringId=?
21:45:51,802 DEBUG SQL:111 - select offering0_.id as id6_0_, offering0_.CREATEDTIMESTAMP as CREATEDT2_6_0_, offering0_.CREATEDUSERID as CREATEDU3_6_0_, offering0_.MODIFIEDTIMESTAMP as MODIFIED4_6_0_, offering0_.MODIFIEDUSERID as MODIFIED5_6_0_, offering0_.CATEGORYID as CATEGORYID6_0_, offering0_.DESCRIPTION as DESCRIPT7_6_0_, offering0_.IMAGEPATH as IMAGEPATH6_0_, offering0_.VENDORID as VENDORID6_0_ from OFFERINGS offering0_ where offering0_.id=?
21:45:51,812 DEBUG SQL:111 - select ofermessag0_.offeringId as offeringId6_1_, ofermessag0_.id as id1_, ofermessag0_.id as id7_0_, ofermessag0_.CREATEDTIMESTAMP as CREATEDT2_7_0_, ofermessag0_.CREATEDUSERID as CREATEDU3_7_0_, ofermessag0_.MODIFIEDTIMESTAMP as MODIFIED4_7_0_, ofermessag0_.MODIFIEDUSERID as MODIFIED5_7_0_, ofermessag0_.MESSAGEDESCRIPTION as MESSAGED6_7_0_, ofermessag0_.OFFERINGID as OFFERINGID7_0_, ofermessag0_.VENDORID as VENDORID7_0_ from OFFERINGMESSAGES ofermessag0_ where ofermessag0_.offeringId=?
21:45:51,832 DEBUG SQL:111 - update OFFERINGMESSAGES set offeringId=null where offeringId=?
21:45:51,832 WARN  JDBCExceptionReporter:233 - SQL Error: 90006, SQLState: 90006
21:45:51,832 ERROR JDBCExceptionReporter:234 - NULL not allowed for column "OFFERINGID"; SQL statement:
update OFFERINGMESSAGES set offeringId=null where offeringId=? [90006-129]
21:45:51,842 WARN  JDBCExceptionReporter:233 - SQL Error: 90006, SQLState: 90006
21:45:51,842 ERROR JDBCExceptionReporter:234 - NULL not allowed for column "OFFERINGID"; SQL statement:
update OFFERINGMESSAGES set offeringId=null where offeringId=? [90006-129]
21:45:51,842 ERROR AbstractFlushingEventListener:324 - Could not synchronize database state with session
org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update
   at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
   at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128)
   at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
   at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
   at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:186)
   at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
   at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
   at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
   at com.shahkaar.dao.hibernatedao.OfferingDAO.deleteOffering(OfferingDAO.java:56)
   at com.shahkaar.dao.hibernatedao.OfferingDAO.deleteOfferings(OfferingDAO.java:43)
   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:307)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:196)
   at $Proxy34.deleteOfferings(Unknown Source)
   at com.shahkaar.service.impl.DeleteOfferingService.doExecute(DeleteOfferingService.java:39)
   at com.shahkaar.service.BaseService.execute(BaseService.java:50)
   at com.shahkaar.service.impl.DeleteOfferingService.execute(DeleteOfferingService.java:33)
   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:307)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
   at org.springframework.aop.aspectj.MethodInvocationProceedingJoinPoint.proceed(MethodInvocationProceedingJoinPoint.java:80)
   at com.shahkaar.common.LoggingAspect.logMessage(LoggingAspect.java:44)
   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.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:622)
   at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:611)
   at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:65)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
   at $Proxy37.execute(Unknown Source)
   at com.shahkaar.beans.OfferingListBean.removeOffering(OfferingListBean.java:57)
   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.apache.el.parser.AstValue.invoke(AstValue.java:262)
   at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:281)
   at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:68)
   at javax.faces.component.MethodBind


Sani


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.