Add test for HHH-8314
This commit is contained in:
parent
b9185ac43b
commit
97304a291d
|
@ -23,6 +23,7 @@
|
|||
*/
|
||||
package org.hibernate.test.annotations.id;
|
||||
|
||||
import org.hibernate.test.annotations.id.entities.Hotel;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.hibernate.Session;
|
||||
|
@ -49,12 +50,51 @@ import org.hibernate.testing.junit4.BaseCoreFunctionalTestCase;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Emmanuel Bernard
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public class IdTest extends BaseCoreFunctionalTestCase {
|
||||
|
||||
@Test
|
||||
public void testNoGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
Transaction tx = s.beginTransaction();
|
||||
Hotel hotel = new Hotel();
|
||||
hotel.setId( 12l );
|
||||
hotel.setName("California");
|
||||
s.saveOrUpdate(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
hotel = (Hotel) s.get(Hotel.class, 12l);
|
||||
assertNotNull(hotel);
|
||||
assertEquals("California", hotel.getName());
|
||||
assertNull(s.get(Hotel.class, 13l));
|
||||
tx.commit();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
//hotel is now detached
|
||||
hotel.setName("Hotel du nord");
|
||||
s.saveOrUpdate(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
|
||||
s = openSession();
|
||||
tx = s.beginTransaction();
|
||||
hotel = (Hotel) s.get(Hotel.class, 12l);
|
||||
assertNotNull(hotel);
|
||||
assertEquals("Hotel du nord", hotel.getName());
|
||||
s.delete(hotel);
|
||||
tx.commit();
|
||||
s.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenericGenerator() throws Exception {
|
||||
Session s = openSession();
|
||||
|
@ -318,7 +358,7 @@ public class IdTest extends BaseCoreFunctionalTestCase {
|
|||
Department.class, Dog.class, Computer.class, Home.class,
|
||||
Phone.class, Tree.class, FirTree.class, Footballer.class,
|
||||
SoundSystem.class, Furniture.class, GoalKeeper.class,
|
||||
BreakDance.class, Monkey.class};
|
||||
BreakDance.class, Monkey.class, Hotel.class };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.hibernate.test.annotations.id.entities;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* Entity with assigned identity
|
||||
*
|
||||
* @author Emmanuel Bernard <emmanuel@hibernate.org>
|
||||
*/
|
||||
@Entity
|
||||
public class Hotel {
|
||||
@Id
|
||||
private Long id;
|
||||
|
||||
private String name;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue