• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

list objects present in hibernate session

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am facing a problem in an application, It creates a new persistent object and puts a reference object in it as a foreign key. But when it goes to commit the newly created object at the end (there is lot of code in between), the foreign key has been updated to null. This gives a constraint violation for not null field. I have debugged the code but could not find the place where the reference is being updated to null.

Is there any way I can check at each point, what all objects are there in the hibernate session, or any other way to debug and nail the issue?

Thanks,
Me
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can enable show sql in hibernate.cfg.xml file to check, what is the sql query generated by Hibernate.
 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have already enabled show SQL but it doesn't show the values being saved, only the parametrized query is shown.
 
xsunil kumar
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you post both entities and their mapping. so that we can debug the relationship between entities.
 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following hbm mapping



Here the status_id is defined as a not-null field in databade.

In the code I was creating a new object for childInstrumentCrossRefs, putting an existing InstrumentStatus into it and attaching it with the parent InstrumentCrossRef. There are some updates in the parent object as well.

As the set is using cascade update, I am updating the parent object only and all its child objects should also be saved. However, I get a constraint violation exception for the field STATUS_ID.

When I updated the cascade to 'none' for the childInstrumentCrossRefs, and updated the code to save individual instances of parent and children, the code started working fine.

I read somewhere that cascade='save-update' is not recommended for many-to-many 'http://docs.jboss.org/hibernate/core/3.3/reference/en/html/objectstate.html#objectstate-transitive'.
Can any one elaborate the reason for of it?

Thanks,
Me
 
M Mehta
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can anyone please help me on this?
 
reply
    Bookmark Topic Watch Topic
  • New Topic