I do a transaction, doing an update on an entity column and it gives an ORA-12899 (Value Too Large for Column).
In the next transaction (I repeat it), I fix the size error to avoid length error (ORA-12899), it should go fine but now it throws an org.hibernate.StaleObjectStateException.
ERROR ExceptionTranslator:35 - concurrency error : Object of class [Entityr] with identifier [565]: optimistic locking failed; nested exception is org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [Entityr#323]
In the entity I use @Cache @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
And one column @Version @Column(name = “VERSION”) @Version
I think it can be related with OptimisticLockType, but I read about problems with the annotation @Version or because of second level cache (I have it enabled with transactinal strategy)
jpaProperties.put(“hibernate.cache.use_second_level_cache”, true); @Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
How do you think I can fix it? I know I should’t allow the first error (ORA-12899), but I don’t want any blocking error.
On first transaction (with an ORA error) hibernate should do rollback and restore the previous object version in the cache (it should restore all the object). Second transaction should work because is a new and correct object. It happens in my local computer (DB in my local too), with no other user interactions.
final Properties jpaProperties = new Properties();
jpaProperties.put(“hibernate.cache.use_second_level_cache”, true);
jpaProperties.put(“hibernate.cache.use_query_cache”, true);
jpaProperties.put(“hibernate.cache.infinispan.cachemanager”, “java:jboss/infinispan/hibernate”);
jpaProperties.put(“hibernate.transaction.jta.platform”, “org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform”); // → It is on a JBoss server
jpaProperties.put(“hibernate.cache.region.factory_class”, “org.jboss.as.jpa.hibernate4.infinispan.InfinispanRegionFactory”);
factory.setPersistenceUnitName(“testPU”);
factory.setPackagesToScan(“org.test.rec”);
Everything works fine if there is not an ORA error at one transaction. I think I have no more Hibernate configuration…
Even if you start a new transaction, as soon as an error happens in a session, the session should not be used any more. You will have to create a new session for the new transaction.
Its like this. It is a transaction inside the services class (as indicated at execution(* org.test.rec..service….*(…)))
public void update(RecognitionHlDto entry) throws BusinessException {
final LocalDateTime now = new LocalDateTime(System.currentTimeMillis());
final RecordDto recordDto = new RecordDto(entry.getRecord());
final Long idRecord = Long.parseLong(entry.getRecord().getIdentifiers().get(0).getValue());
final Record recordBBDD = recordRepository.findOne(idRecord);