-->
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.  [ 4 posts ] 
Author Message
 Post subject: Hibernate selecting, but not inserting ... but not always.
PostPosted: Wed Jan 16, 2008 11:54 am 
Newbie

Joined: Thu May 10, 2007 4:12 am
Posts: 3
Hi,

I am finding that when I execute my code one way, Hibernate works fine. But when I execute it slightly differently, Hibernate will never execute any insert SQLs. I'll try and explain ....

I should probably make it clear up front that I am using the Spring framework, and it could be something at this level causing the problem.

Now, when I execute my business method, as part of a unit test, part of the execution of that method calls Session.merge() and my object is persisted. Everything works as expected.

But, when that same method is executed as a result of a Spring Quartz job (Quartz is a scheduling framework), the call to Session.merge() does not result in any INSERT statements being executed. I have turned on SQL logging and can see that SELECT statements are executed, but no insert statements.

Session.merge() does not throw any exceptions, and a call to Session.flush() immediatly after merge() has no effect.

Any suggestions on what I can look at to try and get this working?

Thanks

robin

Hibernate version: 3.2.4.sp1

Name and version of the database you are using: Oracle 10


Top
 Profile  
 
 Post subject: Re: Hibernate selecting, but not inserting ... but not alway
PostPosted: Wed Jan 16, 2008 1:39 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Is the spring job in scope of a transaction? This kind of problem can be a result of bad transaction wiring. With no transaction in scope hibernate might not know when to flush to database.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 16, 2008 1:47 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Some possibilities:

-some spring misconfiguration. Make sure that you have correctly implemented the open-session-in-view pattern, and that you are intercepting the methods in question so that they are wrapped in some sort of transaction.

-You have more than one session floating over there. Make sure that your session comes from only one configuration object, don't create more than one configuration during the lifetime of your program.

If Spring is set up correctly, merge() has no effect, as far as I know.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 21, 2008 7:00 am 
Newbie

Joined: Thu May 10, 2007 4:12 am
Posts: 3
You were both right - it was the lack of a transaction that was causing my problem. My unit tests were loading a slightly different Spring context file to that used by the deployed application.

I noticed that transactions were being created via AOP, but not around this particular business service in the deployed application.

I presume that calling the business service when I ran it as a unit test AbstractTransactionalDataSourceSpringContextTests handled the transaction somehow.

Thank you for your help.


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