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

DoubleDenim do-not-reply at jboss.com
Sat Nov 10 22:14:28 EST 2007


OK, I've been trying to figure this one out for about a week now, and it seems I have tried everything to try and make sense what is going on.

One thing that stands out that I don't quite understand is the following. To explain what is happening i'll describe the heirarchy of the methods in question.

I have a session bean which handles all of my general business logic, then a persistence manager bean that handles any interaction with my persistence layer (sending and retrieving Objects to and from my db via the EntityManager). EG:
SessionBean.methodBlah()-->PersistenceManagerBean.methodWhatever()

Some where in SessionBean.methodA() I have a line which calls the persistenceManager, which deletes elements off an object which is named session (yes there are too many things called session), the SQL output is as follows, which appears to be fine:
...........
  | 01:21:25,359 INFO  [STDOUT] Hibernate: update session set session_rate_id=? where session_id=?
  | 01:21:25,359 INFO  [STDOUT] Hibernate: delete from session_rate where session_return_location_id=?
  | 01:21:25,375 INFO  [STDOUT] Hibernate: delete from session_rate where session_return_location_id=?
  | 01:21:25,375 INFO  [STDOUT] Hibernate: delete from session_return_location where session_departure_location_id=?
  | 01:21:25,468 INFO  [STDOUT] Hibernate: delete from session_rate where session_return_location_id=?
  | 01:21:25,468 INFO  [STDOUT] Hibernate: delete from session_rate where session_return_location_id=?
  | 01:21:25,484 INFO  [STDOUT] Hibernate: delete from session_return_location where session_departure_location_id=?
  | 01:21:25,484 INFO  [STDOUT] Hibernate: delete from session_departure_location where session_provider_id=?
  | 01:21:25,562 INFO  [STDOUT] Hibernate: delete from session_rate where session_return_location_id=?
  | 01:21:25,578 INFO  [STDOUT] Hibernate: delete from session_return_location where session_departure_location_id=?
  | 01:21:25,578 INFO  [STDOUT] Hibernate: delete from session_departure_location where session_provider_id=?

Then there is another call to the persisence manager from this method followed by a return as follows:



  | persistenceManager.updateSession(session);
  | return response;
  | 

On performing the first line persistenceManager.updateSession(session);
i get the following SQL output which is fine:



......
  | 01:21:28,484 INFO  [STDOUT] Hibernate: select providerlo0_.provider_location_id as provider1_36_, providerlo0_.address as address36_, providerlo0_.name as name36_, providerlo0_.location_id as location6_36_, providerlo0_.code as code36_, providerlo0_.creation_date as creation5_36_, providerlo0_.provider_id as provider7_36_ from provider_location providerlo0_ where providerlo0_.provider_id=? and providerlo0_.location_id=?
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_departure_location (enabled, creation_date, session_provider_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?)
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_return_location (enabled, creation_date, departure_date, return_date, session_departure_location_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?, ?, ?)
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_return_location (enabled, creation_date, departure_date, return_date, session_departure_location_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?, ?, ?)
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_departure_location (enabled, creation_date, session_provider_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?)
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_return_location (enabled, creation_date, departure_date, return_date, session_departure_location_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?, ?, ?)
  | 01:21:28,484 INFO  [STDOUT] Hibernate: insert into session_return_location (enabled, creation_date, departure_date, return_date, session_departure_location_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?, ?, ?)
  | 01:21:28,500 INFO  [STDOUT] Hibernate: insert into session_departure_location (enabled, creation_date, session_provider_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?)
  | 01:21:28,500 INFO  [STDOUT] Hibernate: insert into session_return_location (enabled, creation_date, departure_date, return_date, session_departure_location_id, provider_location_id, updated_date) values (?, ?, ?, ?, ?, ?, ?)
  | 

However when I step over the line return response; I get this extra bit of sql being performed! Followed by a constraint error.

01:21:30,703 INFO  [STDOUT] Hibernate: update session set affiliate_id=?, session_rate_id=?, customer_id=?, credit_card_details_id=?, reservation_id=?, updated_date=?, step=?, customer_birth_date=?, customer_country_code_1=? where session_id=?
  | 01:21:30,734 WARN  [JDBCExceptionReporter] SQL Error: 1452, SQLState: 23000
  | 01:21:30,734 ERROR [JDBCExceptionReporter] Cannot add or update a child row: a foreign key constraint fails (`myapplication/session`, CONSTRAINT `FK76508296B1CFEF2D` FOREIGN KEY (`session_rate_id`) REFERENCES `session_rate` (`session_rate_id`))
  | 01:21:30,734 ERROR [AbstractFlushingEventListener] Could not synchronize database state with session


This doesn't make sense to me as all I am doing is returning a value and there is nothing being called, let alone anything being called that relates to db persistence.

Am I missunderstanding how my persistence layer works?

Any assistance would be greatly appreciated

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

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



More information about the jboss-user mailing list