Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Debugging hibernate

 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey,

i work with Ejb3 (jboss + hibernate).
i get an excpetion when i tried to execute query because hibernate execute flush before the query and in the flush it complained that it try to persist deleted object. (i dont get any furher information)
I debug my code and i dont call to any persist during this sequence (there is also no case of changes that can cause to cascade).

I have JAD plugin in my eclipse and i put a breakpoint in the hibernate class , but it didnt stop.

Please help me to think on any idea to understand which object it try to persist.

ps. hibernate trace didnt help.
Thank you
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So it would all occur in the midst of a "transaction/session". Can you post that code?

Mark
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, i cant post the code becaus this is a long a nd complex dequence.

I know that it difficult to give solution without code , but if you can think on tips on how to debug this issue i will be greatfull.
i set hibernate log to trace , but there are no inforamtion.
I need to know which object it try to persist. (i dont call to persist, i guess its due to cascade)

Thak you
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I can't help you with your exact code. So all I can do is give some basic advice.

1. Keep your Hibernate Sessions short. The longer you keep them open the more full the Session gets holding all the objects that it is managing in multiple Maps, so the more you put in there, the bigger the memory it takes up. Also, the tougher it becomes to debug and figure out what is happening to those objects that Hibernate is managing. Your example is a perfect example. At some point in your code your remove an object that is being managed by Hibernate, that Hibernate now has as an object to be removed, and then you try to persist it, which Hibernate already knows that it was removed and that you can't persist a removed object.

Mark
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try turning on show_sql to see what statements Hibernate is trying to run in the flush.

Basically a flush, will go through the managed objects and persist or delete the objects that have changes. So when an object is managed by a Hibernate session it tracks all the changes you do, so even if you don't have a session.saveOrUpdate() anywhere, something as simple as myObject.setSomeValue(value), will be tracked and Hibernate knows when it flushes that a statement will need to run against the database, this could be an insert, update, or delete.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic