本文整理了Java中javax.persistence.EntityManager.remove()
方法的一些代码示例,展示了EntityManager.remove()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EntityManager.remove()
方法的具体详情如下:
包路径:javax.persistence.EntityManager
类名称:EntityManager
方法名:remove
[英]Remove the entity instance.
[中]删除实体实例。
代码示例来源:origin: spring-projects/spring-integration-samples
@Transactional
public void remove() {
if (this.entityManager == null) {
this.entityManager = entityManager();
}
if (this.entityManager.contains(this)) {
this.entityManager.remove(this);
} else {
LoanShark attached = this.entityManager.find(this.getClass(), this.id);
this.entityManager.remove(attached);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@Priority(10)
public void initData() {
EntityManager em = getEntityManager();
// Revision 1 - add
em.getTransaction().begin();
ObjectUserTypeEntity entity = new ObjectUserTypeEntity( "builtInType1", "stringUserType1" );
em.persist( entity );
em.getTransaction().commit();
id = entity.getId();
// Revision 2 - modify
em.getTransaction().begin();
entity = em.find( ObjectUserTypeEntity.class, entity.getId() );
entity.setUserType( 2 );
entity = em.merge( entity );
em.getTransaction().commit();
// Revision 3 - remove
em.getTransaction().begin();
entity = em.find( ObjectUserTypeEntity.class, entity.getId() );
em.remove( entity );
em.getTransaction().commit();
em.close();
}
代码示例来源:origin: Impetus/Kundera
public void deleteCounter()
{
EntityManager em = emf.createEntityManager();
Counters counters = new Counters();
counters = em.find(Counters.class, id3);
Assert.assertNotNull(counters);
Assert.assertNotNull(counters.getCounter());
em.remove(counters);
EntityManager em1 = emf.createEntityManager();
counters = em1.find(Counters.class, id3);
Assert.assertNull(counters);
em.close();
}
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentDoublePrimitive studentMax = em.find(StudentDoublePrimitive.class, maxValue);
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentDoublePrimitive.class, maxValue);
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
@Override
public void remove(AuthorizationCodeEntity authorizationCodeEntity) {
AuthorizationCodeEntity found = manager.find(AuthorizationCodeEntity.class, authorizationCodeEntity.getId());
if (found != null) {
manager.remove(found);
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@Priority(10)
public void initData() {
EntityManager entityManager = getEntityManager();
try {
// Revision 1 - insertion
Professor professor = new Professor();
Student student = new Student();
professor.getStudents().add( student );
student.getProfessors().add( professor );
entityManager.getTransaction().begin();
entityManager.persist( professor );
entityManager.persist( student );
entityManager.getTransaction().commit();
entityManager.clear();
// Revision 2 - deletion
entityManager.getTransaction().begin();
professor = entityManager.find( Professor.class, professor.getId() );
student = entityManager.find( Student.class, student.getId() );
entityManager.remove( professor );
entityManager.remove( student );
// the issue is student.getProfessors() throws a LazyInitializationException.
entityManager.getTransaction().commit();
}
finally {
entityManager.close();
}
}
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentDoubleWrapper studentMax = em.find(StudentDoubleWrapper.class, maxValue);
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentDoubleWrapper.class, maxValue);
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
@Override
@Transactional(value="defaultTransactionManager")
public void remove(ApprovedSite approvedSite) {
ApprovedSite found = manager.find(ApprovedSite.class, approvedSite.getId());
if (found != null) {
manager.remove(found);
} else {
throw new IllegalArgumentException();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@Priority(10)
public void initData() {
EntityManager entityManager = getOrCreateEntityManager();
try {
// Revision 1
SimpleEntity se = new SimpleEntity();
se.setData( "data" );
entityManager.getTransaction().begin();
entityManager.persist( se );
entityManager.getTransaction().commit();
entityManager.clear();
entityId = se.getId();
// Revision 2
entityManager.getTransaction().begin();
se = entityManager.find( SimpleEntity.class, se.getId() );
se.setData( "data2" );
entityManager.merge( se );
entityManager.getTransaction().commit();
// Revision 3
entityManager.getTransaction().begin();
se = entityManager.find( SimpleEntity.class, se.getId() );
entityManager.remove( se );
entityManager.getTransaction().commit();
}
finally {
entityManager.close();
}
}
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentLongPrimitive studentMax = em.find(StudentLongPrimitive.class, getMaxValue(long.class));
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentLongPrimitive.class, getMaxValue(long.class));
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
@Override
@Transactional(value="defaultTransactionManager")
public void remove(BlacklistedSite blacklistedSite) {
BlacklistedSite found = manager.find(BlacklistedSite.class, blacklistedSite.getId());
if (found != null) {
manager.remove(found);
} else {
throw new IllegalArgumentException();
}
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testConverterIsNotIncorrectlyApplied() {
Widget w = new Widget();
w.setId( 1 );
w.setDimension( new BigDecimal( "1.0" ) );
w.setCost( new Money( "2.0" ) );
EntityManager em = entityManagerFactory().createEntityManager();
em.getTransaction().begin();
em.persist( w );
em.getTransaction().commit();
em.close();
em = entityManagerFactory().createEntityManager();
em.getTransaction().begin();
Widget recorded = em.find( Widget.class, 1 );
assertEquals( 1, recorded.getId() );
em.remove(recorded);
em.getTransaction().commit();
em.close();
}
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentCouchDBCharacter studentMax = em.find(StudentCouchDBCharacter.class, getMaxValue(Character.class));
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentCouchDBCharacter.class, getMaxValue(Character.class));
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: mitreid-connect/OpenID-Connect-Java-Spring-Server
@Override
@Transactional(value="defaultTransactionManager")
public void remove(WhitelistedSite whitelistedSite) {
WhitelistedSite found = manager.find(WhitelistedSite.class, whitelistedSite.getId());
if (found != null) {
manager.remove(found);
} else {
throw new IllegalArgumentException();
}
}
代码示例来源:origin: hibernate/hibernate-orm
entity = em.find( PropertyNotUpdatableEntity.class, entity.getId() );
entity.setData( "modified data" );
entity.setConstantData1( null );
em.getTransaction().commit();
em.close();
entity = em.find( PropertyNotUpdatableEntity.class, entity.getId() );
entity.setData( "another modified data" );
entity.setConstantData2( "invalid data" );
em.remove( entity );
em.getTransaction().commit();
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentMongoShortPrimitive studentMax = em.find(StudentMongoShortPrimitive.class, getMaxValue(Short.class));
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentMongoShortPrimitive.class, getMaxValue(Short.class));
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public void delete(Referenced securePayment) {
if (!em.contains(securePayment)) {
securePayment = em.find(securePayment.getClass(), securePayment.getId());
}
em.remove(securePayment);
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
@Priority(10)
public void initData() throws Exception {
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
EntityManager entityManager = getEntityManager();
try {
TestEntity entity = new TestEntity( ENTITY_ID, "Fab" );
entityManager.persist( entity );
OtherTestEntity other = new OtherTestEntity( OTHER_ENTITY_ID, "other" );
entity.addOther( other );
entityManager.persist( entity );
entityManager.persist( other );
}
finally {
entityManager.close();
TestingJtaPlatformImpl.tryCommit();
}
TestingJtaPlatformImpl.INSTANCE.getTransactionManager().begin();
entityManager = getEntityManager();
try {
TestEntity entity = entityManager.find( TestEntity.class, ENTITY_ID );
OtherTestEntity other = entityManager.find( OtherTestEntity.class, OTHER_ENTITY_ID );
entityManager.remove( entity );
entityManager.remove( other );
}
finally {
entityManager.close();
TestingJtaPlatformImpl.tryCommit();
}
}
代码示例来源:origin: Impetus/Kundera
public void testDelete(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
StudentHBaseDate studentMax = em.find(StudentHBaseDate.class, getMaxValue(Date.class));
Assert.assertNotNull(studentMax);
Assert.assertEquals(getMaxValue(short.class), studentMax.getAge());
Assert.assertEquals("Kuldeep", studentMax.getName());
em.remove(studentMax);
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
studentMax = em.find(StudentHBaseDate.class, getMaxValue(Date.class));
Assert.assertNull(studentMax);
em.close();
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
public void delete(CodeType codeType) {
if (!em.contains(codeType)) {
codeType = (CodeType) em.find(CodeTypeImpl.class, codeType.getId());
}
em.remove(codeType);
}
内容来源于网络,如有侵权,请联系作者删除!