tm.begin();
em.persist(new Fruit("apple", 1));
tm.commit();
tm.begin();
Fruit.enableSimulationFlag();
try {
Fruit fruit = em.find(Fruit.class, 1);
assertNull(fruit);
} catch(PersistenceException failed) {
fail("EntityManager.find() should return null but instead threw an exception", failed);
} finally {
Fruit.clearSimulationFlag():
}
}
@Entity
public class Fruit {
static boolean simulateIronJacamarFailFast = false;
public Fruit() {
if ( simulateIronJacamarFailFast ) {
throw new PersistenceException("org.hibernate.exception.GenericJDBCException: Unable to acquire JDBC Connection", due to IJ throwing "javax.resource.ResourceException: IJ000459: Transaction is not active: tx=Local transaction");
}
}
static public void clearSimulationFlag() {
simulateIronJacamarFailFast = false;
}
static public void enableSimulationFlag() {
simulateIronJacamarFailFast = true;
}
Long id;
@Id
@GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}