[jboss-user] [EJB 3.0] - constraint violation issue.

DoubleDenim do-not-reply at jboss.com
Mon Nov 5 23:28:39 EST 2007


I've been trying to solve this issue for a day now. And i think it pretty much comes down to a lack of understanding of the life cycle.

I've got a session bean that calls a method on my persistence manager, passing it a persistence object called "session".

this method goes through my session persistence object and deletes attached elements of it, however it throws a constraint violation when i try to remove the SessionRate(s), saying there is a FK constraint on session.sessionRate, even though i have removed this relationship by setting session.sessionRate to null on my first line.  So even though I have removed the value that is causing the constraint violation in the first line, i still get code that is run after this causing a constraint violation, therefore nothing gets changed and the whole lot gets rolled back. I am wondering if it is because it is all being done in the same batch/transaction?? see below.



		em.createQuery("update Session s SET s.sessionRate = :sessionRate WHERE s = :session").setParameter("sessionRate",null).setParameter("session",session).executeUpdate();
  | 		for(SessionPartner sessionPartner:session.getSessionPartners())
  | 		{
  | 			for(SessionDepartureLocation sessionDepartureLocation:sessionPartner.getSessionDepartureLocations())
  | 			{
  | 				for(SessionArrivalLocation sessionArrivalLocation:sessionDepartureLocation.getSessionArrivalLocations())
  | 				{
  | 
  | 					em.createQuery("delete SessionRate sr where sr.sessionArrivalLocation = :sessionArrivalLocation").setParameter("sessionArrivalLocation",sessionArrivalLocation).executeUpdate();
  | 				}
  | 				em.createQuery("delete SessionArrivalLocation sal where sal.sessionDepartureLocation = :sessionDepartureLocation").setParameter("sessionDepartureLocation",sessionDepartureLocation).executeUpdate();
  | 			}
  | 
  | 		em.createQuery("delete SessionDepartureLocation sdl where sdl.sessionPartner = :sessionPartner").setParameter("sessionPartner",sessionPartner).executeUpdate();
  | 		}

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4102058#4102058

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4102058



More information about the jboss-user mailing list