Jpa 2 hibernate setting a lock on EntityManager.find?

I cannot reproduce. With the following entity.

I cannot reproduce. With the following entity: @Entity public class Foo { @Id private Integer id; private String name; @Version private Integer version; ... } The following snippet just works: EntityManager em = getEntityManager(); Foo foo = em. Find(Foo.

Class, 1, LockModeType. WRITE); assertNotNull(foo); foo. SetName("baz"); em.flush(); And reads and updates the entity using optimistic locking, with version update: 10:21:42.223 main DEBUG org.hibernate.

SQL - select foo0_. Id as id25_0_, foo0_. Name as name25_0_, foo0_.

Version as version25_0_ from Foo foo0_ where foo0_. Id=? 10:21:42.225 main TRACE org.hibernate.type.

LongType - binding '1' to parameter: 1 10:21:42.229 main TRACE org.hibernate.type. StringType - returning 'bar' as column: name25_0_ 10:21:42.230 main TRACE org.hibernate.type. LongType - returning '0' as column: version25_0_ 10:21:42.246 main DEBUG org.hibernate.

SQL - update Foo set name=? , version=? Where id=?

And version=? 10:21:42.248 main TRACE org.hibernate.type. StringType - binding 'baz' to parameter: 1 10:21:42.249 main TRACE org.hibernate.type.

LongType - binding '1' to parameter: 2 10:21:42.249 main TRACE org.hibernate.type. LongType - binding '1' to parameter: 3 10:21:42.250 main TRACE org.hibernate.type. LongType - binding '0' to parameter: 4 Tested with 5.5-Final.

You are not using the same version (I mentioned it explicitly because of issues like HHH-5032). Try with the following dependencies instead (you don't need to specify a dependency on the hibernate-core artifact, you'll get it transitively): org. Bernate hibernate-validator 4.1.0.

Final org. Bernate hibernate-entitymanager 3.5.5-Final jboss jboss 4.2.3. GA provided.

I try with the same version, but still having the issue. – Hugo Sep 10 '10 at 12:46 Great, it seems to work now.. but I found another thing (going to edit the post, little small here) – Hugo Sep 10 '10 at 13:49 @Hugo Ok, glad it's solved. Regarding the new problem, this is another question.So please open a new one (the best practice is to not mix topics) and explain why this test is supposed to throw an exception, I don't see why it should.

– Pascal Thivent Sep 10 '10 at 14:12.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions