本文整理汇总了Java中javax.persistence.EntityManager.contains方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.contains方法的具体用法?Java EntityManager.contains怎么用?Java EntityManager.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.contains方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Transactional(Transactional.TxType.REQUIRED)
@Override
public void run() {
Car car = new Car();
UUID uuid = UUID.randomUUID();
String id = "blue " + uuid.toString();
car.setEngineSize(1);
car.setNumberPlate(id);
carService.addCar(car);
EntityManager em = getEmFromCoord();
if (!em.contains(car)) {
throw new IllegalStateException("Transaction should cause EntityManager to be kept open");
}
readAndUpdate(id);
Car car3 = carService.getCar(id);
if (car3.getEngineSize() != 100) {
throw new IllegalStateException("Engine size should have been changed to 100");
}
carService.deleteCar(id);
Car car2 = carService.getCar(id);
if (car2 != null) {
throw new RuntimeException("Car with id " + id + " should be deleted"); // NOSONAR
}
}
示例2: remove
import javax.persistence.EntityManager; //导入方法依赖的package包/类
@Transactional
public void remove() {
User user = User.findUser(this.getEppn());
user.getCards().remove(this);
EntityManager em = Card.entityManager();
if (em.contains(this)) {
em.remove(this);
} else {
Card attached = Card.findCard(this.getId());
em.remove(attached);
}
}