• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Spring: partly commited Txn issue

 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am debugging a system using Spring and Hibernate where a transaction (declarative) is started by Spring is partly commited even when an eception in generated. By partly I mean half of stuff is commited and other half rolledback.
As the code is spread over number of lines, its not possible for me to paste any code here. I need some advice on how to go about looking for the errant code.

Also should not Spring throw up an error if any commit is called with in a transaction?

Here is part of Spring txn declaration:



Regards,
Vijay
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your "processCall" method could be part of another transaction, which has commit statements.
To do a quick check change your PROPAGATION_REQUIRED to PROPAGATION_NEVER. See if it throws an exception.

Can you also post the code inside your processCall method and also any other method (if present) which calls your processCall method in the scenario where you get a partly committed transaction.
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun,

I am segregating all the calls to hibernate to see if any one of them is forcing a commit.

Thanks for replying.

Vijay
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hibernate session.find() call is commiting the database changes which is quite bizzare. Can somebody explain why hibernate is doing that?

Here is the stack trace that I obtained by forcing an exception on insert:


net.sf.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
at net.sf.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:73)
at net.sf.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:30)
at net.sf.hibernate.impl.BatcherImpl.convert(BatcherImpl.java:325)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:134)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:60)
at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:57)
at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:110)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:456)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:435)
at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:37)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2438)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2391)
at net.sf.hibernate.impl.SessionImpl.autoFlushIfRequired(SessionImpl.java:1820)
at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1577)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1542)

Regards,
Vijay
 
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Hibernate flush mode you are using does not commit everything immediately on a save()/update(). But when you trigger a find, such unflushed data is flushed out immediately before the find is issued on the DB.
 
Sabarish Sasidharan
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can change either the flush mode or force a flush programmatically, if thats what is bothering you.
 
Vijay Kashyap
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sabarish,

Is there any way to search an entity without flushing? I need to keep checking a status flag (set within a table) but at the same time I do not want to flush till transaction is commited. I tried using Flush mode COMMIT but this doesn't reads the updated status flag (Set by some other process).

Regards,
Vijay
reply
    Bookmark Topic Watch Topic
  • New Topic