Note that there are some explanatory texts on larger screens.

plurals
  1. POHibernateException: proxy handle is no longer valid after database violation error
    primarykey
    data
    text
    <p>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.</p> <p>In the loop, after i catch exception of oracle constraint violation :</p> <blockquote> <p>org.hibernate.exception.constraintviolationexception: ora-00001: unique constraint (ccb.sys_c0017085) violated</p> </blockquote> <p>I log problem and try to save another object. Next exception i get is:</p> <blockquote> <p>org.hibernate.HibernateException: proxy handle is no longer valid</p> </blockquote> <p>Sometimes it occurs only one time after each ora error but sometimes it repeats for more objects (iterations).</p> <p>How to handle this exception &amp; how to make save operation possible?</p> <p>I'm using Spring 3.1.3 and Hibernate 4.1.7.</p> <p>[edit] Some code sample:</p> <pre><code>@Service public class ServiceForRecord { @Transactional public Record saveRecord(Record record, String user) { Record obj = record; // some validation &amp; seting internal values getHibernateTemplate().saveOrUpdate(obj) return obj; } ... </code></pre> <p>and in my loop i do:</p> <pre><code>//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 </code></pre> <p>[edit] Stack trace:</p> <pre><code>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 </code></pre> <p>[edit] last thing i noticed is that it does not occur on MS SQL Server, only on Oracle</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload