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: AssertionFailure: don't flush the Session after an exception
PostPosted: Tue Oct 19, 2010 1:29 pm 
Newbie

Joined: Thu Dec 07, 2006 6:47 pm
Posts: 3
I am using Hibernate 3.5.6 + Hibernate JPA 2.0 in a Spring MVC 3.0.3 web application context. I have a one-to-many relationship modeled (similar to below). If all the data passes validations, the parent and associated child instances get saved to the database as expected. However, say I null out a single non-nullable property (e.g. Child.childName) of a single record to reproduce a database exception, two bad things happen:

1. Inconsistent data set is persisted, up to the point of violating data
2. Following Exception is thrown...
Quote:
2010-10-19 12:07:31,721 ERROR [org.hibernate.AssertionFailure] - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
org.hibernate.AssertionFailure: null id in com.hsemuni.internal.newissues.domain.NewIssuePricing entry (don't flush the Session after an exception occurs)
at org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)
at org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
...

I had to implement a filter to circumvent LazyInitiationException error when trying to get detailed children view for a selected parent instance, based on the following Hibernate Community forum post... OpenSessionInView & DML operations This worked out well, in that I was able to get around the LazyInitiationException error, but I am wondering if it is somehow responsible for the error I am getting. The reason for my suspicion is because when I try to do the same thing in a console based application, the session seems to rollback and I simply encounter the database violation exception.
Code:
@Entity
@Table(name="parent")
public class Parent implements Serializable {

  @Id
  @GeneratedValue
  @Column(name="parent_id")
  private Long parentID;

  @Column(name="name")
  private String parentName;

  @OneToMany(mappedBy="parent", fetch=FetchType.LAZY, cascade = {CascadeType.ALL})
  private List<Child> children;
}

@Entity
@Table(name="child")
public class Child implements Serializable {

  @Id
  @GeneratedValue
  @Column(name="child_id")
  private Long childID;

  @Column(name="name")
  private String childName;

  @ManyToOne(fetch=FetchType.LAZY, cascade={CascadeType.ALL})
  @JoinColumn(name="parent_id")
  private Parent parent;
}

My service component issues the DAO's save method as follows:
Code:
   @Transactional(readOnly=false, propagation=Propagation.REQUIRES_NEW)
   public Parent saveParent(Parent parent) {
      return parentDAO.saveParent(parent);
   }

Can anyone help with this?

Thanks!

Ashwin


Top
 Profile  
 
 Post subject: Re: AssertionFailure: don't flush the Session after an exception
PostPosted: Fri Nov 12, 2010 1:41 pm 
Newbie

Joined: Thu Dec 07, 2006 6:47 pm
Posts: 3
Turns out I was performing [Spring] component scanning in both the root context and that defined by DispatcherServlet starting from the same base package. The latter component scanning caused a "transaction-less" @Service to be injected into the web controller, which naturally robs the thread of any transactional capabilities.

See http://forum.springsource.org/showthread.php?t=97629 for further details.

Thanks for your help!

Ashwin


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.