-->
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.  [ 3 posts ] 
Author Message
 Post subject: AssertionFailure: null id XXXX Hibernate + spring
PostPosted: Thu Dec 01, 2011 5:49 pm 
Newbie

Joined: Thu Apr 22, 2010 2:25 pm
Posts: 6
I am using spring + hibernate,
i am getting following error after saveOrUpdate into a table fails and i am trying to execute SQL query after failure

The code in Controller as is below

Code:
@Controller
@Transactional
public class AirportController {

@RequestMapping(value = "/displayAddAirport")
    public String displayAddAirport(@ModelAttribute("newairport") Airport newairport,Model model)throws Exception{
     
     try{
     airportDao.saveAirport(newairport);
 
     }
   catch(Exception exc){
// trying to read some other table data fails
   airtportDao.getData();
  }
}
}

The error is

Code:
org.hibernate.AssertionFailure: null id in XXXXXXX entry (don't flush the Session after an exception occurs)
   org.hibernate.event.def.DefaultFlushEntityEventListener.checkId(DefaultFlushEntityEventListener.java:82)
   org.hibernate.event.def.DefaultFlushEntityEventListener.getValues(DefaultFlushEntityEventListener.java:190)
   org.hibernate.event.def.DefaultFlushEntityEventListener.onFlushEntity(DefaultFlushEntityEventListener.java:147)
   org.hibernate.event.def.AbstractFlushingEventListener.flushEntities(AbstractFlushingEventListener.java:219)
   org.hibernate.event.def.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:99)
   org.hibernate.event.def.DefaultAutoFlushEventListener.onAutoFlush(DefaultAutoFlushEventListener.java:58)
   org.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1185)
   org.hibernate.impl.SessionImpl.list(SessionImpl.java:1261)
   org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
   org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:921)
   org.springframework.orm.hibernate3.HibernateTemplate$30.doInHibernate(HibernateTemplate.java:1)
   org.springframework.orm.hibernate3.HibernateTemplate.doExecute(HibernateTemplate.java:406)
   org.springframework.orm.hibernate3.HibernateTemplate.executeWithNativeSession(HibernateTemplate.java:374)
   org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:912)
   org.springframework.orm.hibernate3.HibernateTemplate.find(HibernateTemplate.java:904)


Top
 Profile  
 
 Post subject: Re: AssertionFailure: null id XXXX Hibernate + spring
PostPosted: Thu Dec 01, 2011 6:13 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
You are not supposed to use the session after an exception occurs. Quote from the Hibernate documentation at http://docs.jboss.org/hibernate/core/3. ... exceptions:

Quote:
If the Session throws an exception, including any SQLException, immediately rollback the database transaction, call Session.close() and discard the Session instance. Certain methods of Session will not leave the session in a consistent state. No exception thrown by Hibernate can be treated as recoverable. Ensure that the Session will be closed by calling close() in a finally block.


Top
 Profile  
 
 Post subject: Re: AssertionFailure: null id XXXX Hibernate + spring
PostPosted: Fri Dec 02, 2011 10:32 am 
Newbie

Joined: Thu Apr 22, 2010 2:25 pm
Posts: 6
I am using Spring + hibernate so i am not controlling the session, but spring is, so if i want another session to get some data how can i handle this situation?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.