Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9260759
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:58:32+00:00 2026-06-18T12:58:32+00:00

I have loop to save couple of objects. In loop a call service method

  • 0

I have loop to save couple of objects. In loop a call service method and catch exceptions. Service save method is annotated @Transactional and inside does hibernate saveOrUpdate call.
Service is provided by getBean method of ApplicationContext object. I call it only once before loop.

In the loop, after i catch exception of oracle constraint violation :

org.hibernate.exception.constraintviolationexception: ora-00001: unique constraint (ccb.sys_c0017085) violated

I log problem and try to save another object. Next exception i get is:

org.hibernate.HibernateException: proxy handle is no longer valid

Sometimes it occurs only one time after each ora error but sometimes it repeats for more objects (iterations).

How to handle this exception & how to make save operation possible?

I’m using
Spring 3.1.3 and Hibernate 4.1.7.

[edit]
Some code sample:

@Service
public class ServiceForRecord {
    @Transactional
public Record saveRecord(Record record, String user) {
      Record obj = record;
      // some validation & seting internal values
      getHibernateTemplate().saveOrUpdate(obj)
      return obj;
    }
...

and in my loop i do:

//in params:
serviceClass = ServiceForRecord.class;
entityClass = Record.class;
saveMethod = "saveRecord";
//loop prepare
service = getApplicationContext().getBean(serviceClass);
serviceSave = serviceClass.getMethod("saveRecord", Record.class, String.class);
while (condition) {
entity =  BeanUtils.instantiate(entityClass);
//setup entity
serviceSave.invoke(service, entity, "testUser");
//catch error
} //end while

[edit]
Stack trace:

PreparedStatementProxyHandler(AbstractProxyHandler).errorIfInvalid() line: 63   
PreparedStatementProxyHandler(AbstractStatementProxyHandler).continueInvocation(Object, Method, Object[]) line: 100 
PreparedStatementProxyHandler(AbstractProxyHandler).invoke(Object, Method, Object[]) line: 81   
$Proxy100.clearBatch() line: not available  
NonBatchingBatch(AbstractBatchImpl).releaseStatements() line: 163   
NonBatchingBatch(AbstractBatchImpl).execute() line: 152 
JdbcCoordinatorImpl.getBatch(BatchKey) line: 151    
SingleTableEntityPersister(AbstractEntityPersister).insert(Serializable, Object[], boolean[], int, String, Object, SessionImplementor) line: 2940   
SingleTableEntityPersister(AbstractEntityPersister).insert(Serializable, Object[], Object, SessionImplementor) line: 3403   
EntityInsertAction.execute() line: 88   
ActionQueue.execute(Executable) line: 362   
ActionQueue.executeActions(List) line: 354  
ActionQueue.executeActions() line: 275  
DefaultFlushEventListener(AbstractFlushingEventListener).performExecutions(EventSource) line: 326   
DefaultFlushEventListener.onFlush(FlushEvent) line: 52  
SessionImpl.flush() line: 1210  
SessionImpl.managedFlush() line: 399    
JdbcTransaction.beforeTransactionCommit() line: 101 
JdbcTransaction(AbstractTransactionImpl).commit() line: 175 
HibernateTransactionManager.doCommit(DefaultTransactionStatus) line: 480    
HibernateTransactionManager(AbstractPlatformTransactionManager).processCommit(DefaultTransactionStatus) line: 754   
HibernateTransactionManager(AbstractPlatformTransactionManager).commit(TransactionStatus) line: 723 
TransactionInterceptor(TransactionAspectSupport).commitTransactionAfterReturning(TransactionAspectSupport$TransactionInfo) line: 392    
TransactionInterceptor.invoke(MethodInvocation) line: 120   
ReflectiveMethodInvocation.proceed() line: 172  
AfterReturningAdviceInterceptor.invoke(MethodInvocation) line: 50   
ReflectiveMethodInvocation.proceed() line: 172  
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 202   
$Proxy71.save(Account, String) line: not available  
GeneratedMethodAccessor115.invoke(Object, Object[]) line: not available 
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available   
Method.invoke(Object, Object...) line: not available    
ImportServiceProvider.save(Object, String) line: 380

[edit]
last thing i noticed is that it does not occur on MS SQL Server, only on Oracle

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:58:34+00:00Added an answer on June 18, 2026 at 12:58 pm

    I have different suggestions regarding your issue.

    Suggestion 1 : you are wrongly reusing the same session in all transactions.

    To check this : put a breakpoint in saveRecord and check that the reference to the SessionImpl is different in 2 successive calls.

    Honestly, there are few chances this is your problem because your code is running with MS SQL Server. So the only chance for this suggestion to be correct is that the constraints in MS SQL Server are not the same as the constraints in Oracle. Additionally, I think hibernate will throw a more explicit exception in this case.

    Suggestion 2 : you are hitting a bug in hibernate 4

    There are a few bug reports in hibernate JIRA in this area. (without your code, it’s difficult to say what’s your exact situation). There are good chance the behavior you have is linked to one of those bugs:

    https://hibernate.onjira.com/browse/HHH-7688 (this one is very close to yours, but there some others)

    Is there some workarounds to this bug ?

    I have few suggestions to try :

    set hibernate.jdbc.batch_size to something above 1 . This workaround was suggested here by Michale Wyraz and seems to work.

    Don’t use reflection : not sure it will help, but transaction is handled by aop-proxy, and using reflection may cause to bypass some of the transaction manager code (it shouldn’t, but it’s an hypothesis to check).

    Change the connection release mode : all those bugs (in hibernate JIRA) are more or less related to JdbcConnection management, so changing the connection release mode may at somepoint help you to identify the issue. (I don’t say that changing it is the solution, if you are really hitting a bug in hibernate: your best choice is probably to wait/contribute for the fix)

    Downgrading to hibernate 3.X : Once again I don’t say it’s a solution, but it may indicate that you are really facing a bug in hibernate 4.

    Upgrading to hibernate 4.2+ : As suggested in other answer and regarding recent changes in hibernate base code: simply upgrading hibernate may solve the problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this loop method to display a ViewPager and I set an OnClickListener
I have a PHP loop that does the following: Log in to a web
I have the need to continuously build large strings in a loop and save
In my application i have a loop that executes about 1000 times, inside it
Does anyone have some good information on the usage of the .SaveChanges() method? I
I have loop designed to validate the user input on a question, it was
I have loop for: for (int i = 1; i < 2000; i++) How
I have loop and each iteration of Hash looks like this: [1, {:clid=>1, :nvz=>4,
I'm pretty new to jQuery/JS. But I have loop in jQuery where I would
I have a loop that enters each non-empty text field into a database: foreach

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.