Tagged Questions
0
votes
1answer
63 views
Hibernate @Version causing database foreign key constraint failure
I have two hibernate/JPA entities
@Entity
@Table(name = "conference_room", uniqueConstraints = @UniqueConstraint(columnNames = "code"))
class ConferenceRoom {
@Id
@GeneratedValue(strategy = ...
1
vote
3answers
85 views
Testing Optimistic Locking in Java EE environment
As I understand if a row in a database table is updated simultaneously by multiple threads the database would flag an error.
In our production environment we have 2 Tomcat servers in a cluster. It ...
0
votes
1answer
105 views
Hibernate Optimistic Locking : Not getting any exception
I am trying to update the same row in different transaction to understand the optimistic locking of Hibernate.
But I am not getting any StaleObjectStateException or any other exception.
public void ...
0
votes
1answer
50 views
JPA2.0: Semantic of OPTIMISTIC_FORCE_INCREMENT
I'm quite new to JPA and read this article about locking modes in JPA2.0, which left me with a question regarding the LockModeType.OPTIMISTIC_FORCE_INCREMENT.
Here is an image with an example from ...
0
votes
0answers
139 views
How to avoid optimistic lock exception
I am trying to mock the webservice call,and developed a sample client which forms a dummy request and gets response
now what i do is i implement callable in this client class and put all my business ...
1
vote
2answers
90 views
How to efficiently lock a code block in order to avoid optimistic lock exception
I am not very experienced with Multithreading in Java. What I want is to set a lock for a code block. In my case i want to avoid optimistic lock exceptions, while doing some synchronization for a ...
4
votes
1answer
136 views
How do you implement a coarse-grained optimistic lock in REST?
I have implemented optimistic locking for my REST resources that have 1-to-1 mapping to database tables by passing back a version number which was in the GET back through to the PUT call. If the ...
2
votes
0answers
144 views
EntityManager throws OptimisticLockException when try to delete locked entity in same transaction
Here is my code:
EntityManager em = JPAUtil.createEntityManager();
try {
EntityTransaction tx = em.getTransaction();
try {
//do some stuff here
tx.begin();
...
0
votes
1answer
78 views
Hibernate automatic versioning not working (with Spring)
I am trying to use the automatic versioning of Hibernate but when the update method f of the Session is called I do not see the version field in the where clause of the query nor is the version ...
2
votes
1answer
66 views
Table indexes/pk for Optimistic Locking in JPA
What is the best practice for defining table indexes for entities supporting optimistic locking?
For sure, entity id has to be part of some index in DB to enable fast lookups by id. What about ...
2
votes
0answers
77 views
Weird transaction handling JavaEE 6
Currently I study the JavaEE 6 transaction handling and I'm a little bit stuck.
I simulate a seminar booking engine where someone can book one or more persons on a seminar.
My entity looks like this:
...
1
vote
2answers
104 views
How to catch OptimisticLockException in JavaEE 6?
I wonder what is the best way to catch an OptimisticLockException in JavaEE 6. I have the following EJB:
@Stateless
public class SeminarBooking {
public void bookSeminar(Long seminarId, int ...
0
votes
1answer
210 views
Hibernate's StaleObjectStateException still thrown after entity reloaded
I am playing with a standard optimistic concurrency control scenario with extended session / automatic versioning. I have an entity which I load in the first transaction, present to user for ...
0
votes
1answer
70 views
Optimistic Locking : Two fields that need to be updated
In our old db strukture we have two fields in one table that get updated when we change data.
create table dbo.example(
name varchar(50),
...,
changed smalldatetime, -- here we save the ...
0
votes
1answer
371 views
Recovering from hibernate optimistic locking exception
I have a method like this:
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void doSomeWork(){
Entity = entity = dao.loadEntity();
// do some related work
...
try {
...
0
votes
1answer
206 views
Optimistic locking in web applications
We are building a customer provisioning tool for our multi-tenant application. Multiple users can work on the same configuration and hence we want to avoid conflicts. We know that optimistic locking ...
1
vote
1answer
155 views
Ignore optimistic-locking
I've got the entity that contains @version field.
Sometimes I need to update it in spite of optimistic locking exception.
Can I turn it off somehow in that case? Or I should just reload entity and ...
0
votes
1answer
323 views
How to throw OptimisticLockException with hibernate-jpa2.0
I'm currently working on an optimistic-locking management in my project.
We use JPA 2.0 (hibernate-jpa2.0-api-1.0.1.Final) and the datasource is provided by JBoss 7.
What I did
In my entity ...
3
votes
2answers
600 views
Hibernate. Optimistic lock. Selects version even though it generates it
I have an entity:
<class name="name.dargiri.model.Entity" table="ENTITY" optimistic-lock="version">
<version name="version" column="ver" type="long" />
</class
If the Entity is ...
3
votes
1answer
612 views
JPA: How does Read Lock work?
I am trying to understand whats the effect of calling EntityManager.lock(entity, LockModeType.READ). The API documentation sounds very confusing for me.
If I have to concurrent threads and Thread 1 ...
0
votes
2answers
303 views
Active Record Pattern with Optimistic Locking - read before update vs. storing version in application?
I trying to implement the active record pattern using Java/JDBC and MySQL along with optimistic locking for concurrency handling.
Now, I have a 'version_number' field for all the records in a table ...
1
vote
1answer
487 views
Determine Which Entity Caused an Optimistic Lock Exception
I have a web application implemented in JSF and JPA. In the UI, the users can updated a bunch of different entities before choosing to "save" the entire operation. During the save operation, if two ...
1
vote
2answers
2k views
How to code optimistic and pessimistic locking from java code
I know what optimistic and pessimistic locking is, but when you write a java code how do you do it? Suppose I am using Oracle with Java, do I have any methods in JDBC that will help me do that? How ...
2
votes
1answer
478 views
JPA: Setting @JoinColumn(updatable = false) to avoid OptimisticLockException
Given the following the following two entities
@Entity
public class A {
@Version
protected int version;
String basicPropertey;
// getter and setter for basicProperty
}
@Entity
public class ...
0
votes
1answer
142 views
Using Hibernate Versioning in a middle class of a hierarchy
I want to use Hibernate Versioning in my application but I have a problem in a class hierarchy like this :
C extends B and B extends A.
I want to use version in Class B and I don’t need to use version ...
0
votes
1answer
228 views
How to prevent StaleObjectStateException on Query.list()?
I use Hibernate optimistic locks in my software (via @Version annotation). It works quite well, but sometimes I get StaleObjectStateException while trying to merely retrieve some objects from ...
2
votes
1answer
3k views
How to do optimistic locking in hibernate
I am completely new to Hibernate and Spring and in my attempt to learn Spring, Hibernate, Maven etc I only know how to run a hello world example using all of the three. With my basic understanding I ...
0
votes
1answer
438 views
Version property of Parent isn't incrementing if I update child
I'm using JPA 2 with Hibernate 3.x. I have two Entity objects Foo and Bar and the relation is like this -
@Entity
public class Foo{
@Id
private long id;
@OneToOne(cascade = ...
1
vote
1answer
836 views
JPA optimistic lock version handling - version value should be carried onto client side or?
I'm wondering how to handle optimistic lock version property in entity class using JPA (toplink essentials) from server to client and vice versa.
Here is the scenario.
From browser user send ...
1
vote
4answers
565 views
Is it possible to column-level optimistic locking in JPA toplink?
I studied about optimistic locking in JPA, adding @Version annotation with version column in DB and how it is managed by EntityManager etc
The doc says (in my own word) optimistic lock is effective ...
1
vote
1answer
336 views
how to raise OptimisticLockException
Unable to catch optimistic lock exception.
one way to raise OptimisticLockException is by using em.flush()
try{
//some enitity
em.flush()
}
catch(OptimisticLockException ole){}
but i dont ...
7
votes
3answers
3k views
Spring Optimistic Locking:How to retry transactional method till commit is successful
I use Spring 2.5 and Hibernate JPA implementation with Java and "container" managed Transactions.
I have a "after user commit" method that updates data in background and need to be committed ...
0
votes
1answer
658 views
optimistic locking batch update
How to use optimistic locking with batch updates? I am using SimpleJdbcTemplate and for single row I can build update sql that increments version column value and includes version in WHERE clause.
...
2
votes
1answer
737 views
jdbctemplate and optimistic locking
In the project I'm in Hibernate and Spring jdbctemplate are mixed. I added optimistic locking. Hibernate works great with versioning but now I have to tansform all this jdbctemplate code to use ...
3
votes
2answers
415 views
How should I handle persistence in a Java MUD? OptimisticLockException handling
I'm re-implementing a old BBS MUD game in Java with permission from the original developers. Currently I'm using Java EE 6 with EJB Session facades for the game logic and JPA for the persistence. A ...
1
vote
1answer
57 views
Defines JPA behavior for setting same value again?
I wonder, if there is any definition by JPA for the behavior, if you setting equals value for any property. I didn't find any words in the specification.
I've tested with TopLink Essentials and ...
13
votes
5answers
2k views
Java Solutions for Distributed Transactions and/or Data Shared in Cluster
What are the best approaches to clustering/distributing a Java server application ?
I'm looking for an approach that allows you to scale horizontally by adding more application servers, and more ...
9
votes
1answer
10k views
How to use the Hibernate optimistic locking version property on the front end?
Optimistic locking using the version attribute for an entity works fine and is easy to implement:
<version property="VERSION" type="int" column="EX_VERSION" />
The entity has a property of ...