Testcase for HHH-9764
Conflicts: hibernate-core/src/test/java/org/hibernate/test/cache/CollectionCacheEvictionTest.java
This commit is contained in:
parent
a679528f71
commit
840d906cea
|
@ -283,4 +283,40 @@ public class CollectionCacheEvictionTest extends BaseCoreFunctionalTestCase {
|
|||
}
|
||||
s.close();
|
||||
}
|
||||
|
||||
/**
|
||||
* @author Guenther Demetz
|
||||
*/
|
||||
@TestForIssue(jiraKey = "HHH-9764")
|
||||
@Test
|
||||
public void testLockModes() {
|
||||
Session s1 = openSession();
|
||||
s1.beginTransaction();
|
||||
|
||||
Company company1 = (Company) s1.get( Company.class, 1 );
|
||||
|
||||
User user1 = (User) s1.get( User.class, 1 ); // into persistent context
|
||||
|
||||
/******************************************
|
||||
*
|
||||
*/
|
||||
Session s2 = openSession();
|
||||
s2.beginTransaction();
|
||||
User user = (User) s2.get( User.class, 1 );
|
||||
user.setName("TestUser");
|
||||
s2.getTransaction().commit();
|
||||
s2.close();
|
||||
|
||||
|
||||
/******************************************
|
||||
*
|
||||
*/
|
||||
|
||||
// init cache of collection
|
||||
assertEquals( 1, company1.getUsers().size() ); // raises org.hibernate.StaleObjectStateException if 2LCache is enabled
|
||||
|
||||
|
||||
s1.getTransaction().commit();
|
||||
s1.close();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,10 +7,13 @@
|
|||
|
||||
package org.hibernate.test.cache;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -48,4 +51,5 @@ public class Company {
|
|||
public void setUsers(List<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,18 +7,39 @@
|
|||
|
||||
package org.hibernate.test.cache;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.persistence.Version;
|
||||
|
||||
import org.hibernate.annotations.Cache;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
@Entity
|
||||
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
@Table(name="`User`")
|
||||
public class User {
|
||||
@Id
|
||||
int id;
|
||||
|
||||
|
||||
@Version
|
||||
@Column(name="OPTLOCK")
|
||||
private int version;
|
||||
|
||||
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
|
||||
@ManyToOne(fetch = FetchType.LAZY)
|
||||
Company company;
|
||||
|
||||
|
@ -49,4 +70,18 @@ public class User {
|
|||
public void setCompany(Company group) {
|
||||
this.company = group;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue