{code:java} @Test public void testImmutableNaturalIdShouldNotBeChangeable() { // https://hibernate.atlassian.net/browse/HHH-10326 // if there is another @NaturalId for which mutable = true, then the the // @NaturalId with mutable = false can also be changed Session session = sf.openSession(); session.beginTransaction(); Barge first = new Barge(); session.save(first);
FlatBoat flatBoat = new FlatBoat(); flatBoat.setBarge(first); flatBoat.setName("name"); session.save(flatBoat);
session.getTransaction().commit(); session.getTransaction().begin();
Barge second = new Barge(); session.save(second);
flatBoat.setBarge(second);
try { session.getTransaction().commit(); fail(); } catch(HibernateException expected) { assertTrue(expected.getMessage().contains("An immutable natural identifier")); } } {code}
|
|