本文整理了Java中org.hibernate.Hibernate.unproxy()
方法的一些代码示例,展示了Hibernate.unproxy()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hibernate.unproxy()
方法的具体详情如下:
包路径:org.hibernate.Hibernate
类名称:Hibernate
方法名:unproxy
[英]Unproxies a HibernateProxy. If the proxy is uninitialized, it automatically triggers an initialization. In case the supplied object is null or not a proxy, the object will be returned as-is.
[中]解除冬眠催眠。如果代理未初始化,它将自动触发初始化。如果提供的对象为null或不是代理,则对象将按原样返回。
代码示例来源:origin: hibernate/hibernate-orm
/**
* Unproxies a {@link HibernateProxy}. If the proxy is uninitialized, it automatically triggers an initialization.
* In case the supplied object is null or not a proxy, the object will be returned as-is.
*
* @param proxy the {@link HibernateProxy} to be unproxied
* @param entityClass the entity type
* @return the proxy's underlying implementation object, or the supplied object otherwise
*/
public static <T> T unproxy(T proxy, Class<T> entityClass) {
return entityClass.cast( unproxy( proxy ) );
}
}
代码示例来源:origin: hibernate/hibernate-orm
@OneToOne(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
public Child getChild() {
return (Child) Hibernate.unproxy( child );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNullUnproxyReturnsNull() {
assertNull( Hibernate.unproxy( null ) );
assertNull( Hibernate.unproxy( null, Parent.class ) );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNotHibernateProxyShouldThrowException() {
Parent p = new Parent();
Child c = new Child();
p.setChild( c );
doInJPA( this::entityManagerFactory, ( entityManager -> {
entityManager.persist( p );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
assertSame( parent, Hibernate.unproxy( parent ) );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
assertSame( parent, Hibernate.unproxy( parent, Parent.class ) );
} ) );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testInitializedProxyCanBeUnproxied() {
Parent p = new Parent();
Child c = new Child();
p.setChild( c );
doInJPA( this::entityManagerFactory, ( entityManager -> {
entityManager.persist( p );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
Child child = parent.getChild();
assertFalse( Hibernate.isInitialized( child ) );
Hibernate.initialize( child );
Child unproxiedChild = (Child) Hibernate.unproxy( child );
assertEquals( Child.class, unproxiedChild.getClass() );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
Child child = parent.getChild();
assertFalse( Hibernate.isInitialized( child ) );
Hibernate.initialize( child );
Child unproxiedChild = Hibernate.unproxy( child, Child.class );
assertEquals( Child.class, unproxiedChild.getClass() );
} ) );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testNotInitializedProxyCanBeUnproxiedWithInitialization() {
Parent p = new Parent();
Child c = new Child();
p.setChild( c );
doInJPA( this::entityManagerFactory, ( entityManager -> {
entityManager.persist( p );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
Child child = parent.getChild();
assertFalse( Hibernate.isInitialized( child ) );
Child unproxiedChild = (Child) Hibernate.unproxy( child );
assertTrue( Hibernate.isInitialized( child ) );
assertEquals( Child.class, unproxiedChild.getClass() );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent parent = entityManager.find( Parent.class, p.getId() );
Child child = parent.getChild();
assertFalse( Hibernate.isInitialized( child ) );
Child unproxiedChild = Hibernate.unproxy( child, Child.class );
assertTrue( Hibernate.isInitialized( child ) );
assertEquals( Child.class, unproxiedChild.getClass() );
} ) );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testProxyEquality() {
Parent parent = doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent p = new Parent();
p.name = "John Doe";
entityManager.persist( p );
return p;
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent p = entityManager.getReference( Parent.class, parent.getId() );
assertFalse( parent.equals( p ) );
assertTrue( parent.equals( Hibernate.unproxy( p ) ) );
} ) );
doInJPA( this::entityManagerFactory, ( entityManager -> {
Parent p = entityManager.getReference( Parent.class, parent.getId() );
assertFalse( parent.equals( p ) );
assertTrue( parent.equals( Hibernate.unproxy( p, Parent.class ) ) );
} ) );
}
代码示例来源:origin: org.hibernate.orm/hibernate-core
/**
* Unproxies a {@link HibernateProxy}. If the proxy is uninitialized, it automatically triggers an initialization.
* In case the supplied object is null or not a proxy, the object will be returned as-is.
*
* @param proxy the {@link HibernateProxy} to be unproxied
* @param entityClass the entity type
* @return the proxy's underlying implementation object, or the supplied object otherwise
*/
public static <T> T unproxy(T proxy, Class<T> entityClass) {
return entityClass.cast( unproxy( proxy ) );
}
}
代码示例来源:origin: 1and1/cosmo
@Override
public Item findItemByUid(String uid) {
// Prevent auto flushing when looking up item by uid
List<HibItem> results = this.em.createQuery("FROM HibItem h WHERE h.uid= :uid", HibItem.class)
.setParameter("uid", uid).getResultList();
if (!results.isEmpty()) {
return (HibItem) Hibernate.unproxy(results.get(0));
}
return null;
}
代码示例来源:origin: net.oneandone.cosmo/cosmo-core
@Override
public Item findItemByUid(String uid) {
// Prevent auto flushing when looking up item by uid
List<HibItem> results = this.em.createQuery("FROM HibItem h WHERE h.uid= :uid", HibItem.class)
.setParameter("uid", uid).getResultList();
if (!results.isEmpty()) {
return (HibItem) Hibernate.unproxy(results.get(0));
}
return null;
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
private void incrementRootVersion(FlushEntityEvent event, Object root) {
EntityEntry entityEntry = event.getSession().getPersistenceContext().getEntry( Hibernate.unproxy( root) );
if(entityEntry.getStatus() != Status.DELETED) {
event.getSession().lock(root, LockMode.OPTIMISTIC_FORCE_INCREMENT);
}
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
assertTrue(_post.equals( Hibernate.unproxy( post)));
});
内容来源于网络,如有侵权,请联系作者删除!