本文整理匯總了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);
}
}