本文整理了Java中org.hibernate.Hibernate.getClass()
方法的一些代码示例,展示了Hibernate.getClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Hibernate.getClass()
方法的具体详情如下:
包路径:org.hibernate.Hibernate
类名称:Hibernate
方法名:getClass
[英]Get the true, underlying class of a proxied persistent class. This operation will initialize a proxy by side-effect.
[中]获取代理持久类的真实底层类。此操作将通过副作用初始化代理。
代码示例来源:origin: shopizer-ecommerce/shopizer
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("entity.");
builder.append(Hibernate.getClass(this).getSimpleName());
builder.append("<");
builder.append(getId());
builder.append("-");
builder.append(super.toString());
builder.append(">");
return builder.toString();
}
}
代码示例来源:origin: hibernate/hibernate-orm
private Object getIdentifierFromPersister(Object entity) {
Class<?> entityClass = Hibernate.getClass( entity );
final EntityPersister persister;
try {
persister = sessionFactory.getMetamodel().entityPersister( entityClass );
if ( persister == null ) {
throw new IllegalArgumentException( entityClass.getName() + " is not an entity" );
}
}
catch (MappingException ex) {
throw new IllegalArgumentException( entityClass.getName() + " is not an entity", ex );
}
return persister.getIdentifier( entity, null );
}
代码示例来源:origin: shopizer-ecommerce/shopizer
@SuppressWarnings("unchecked")
@Override
public boolean equals(Object object) {
if (object == null) {
return false;
}
if (object == this) {
return true;
}
// l'objet peut être proxyfié donc on utilise Hibernate.getClass() pour sortir la vraie classe
if (Hibernate.getClass(object) != Hibernate.getClass(this)) {
return false;
}
SalesManagerEntity<K, E> entity = (SalesManagerEntity<K, E>) object; // NOSONAR : traité au-dessus mais wrapper Hibernate
K id = getId();
if (id == null) {
return false;
}
return id.equals(entity.getId());
}
代码示例来源:origin: hibernate/hibernate-orm
assertFalse( Hibernate.isInitialized(luc) );
assertFalse( Hibernate.isInitialized(lc) );
assertEquals( UniversityCourse.class, Hibernate.getClass(luc) );
assertEquals( Course.class, Hibernate.getClass(lc) );
assertSame( ( (HibernateProxy) lc ).getHibernateLazyInitializer().getImplementation(), cid );
assertEquals( c.getCourseCode(), "eng5000" );
assertTrue( Hibernate.isInitialized(luc) );
assertTrue( Hibernate.isInitialized(lc) );
assertEquals( UniversityCourse.class, Hibernate.getClass(luc) );
assertEquals( Course.class, Hibernate.getClass(lc) );
assertSame( lc, cid );
assertEquals( c.getCourseCode(), "eng5000" );
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testHistoryOfTnae1_id() {
// load original "tnae1" TargetNotAuditedEntity to force load "str1" UnversionedStrTestEntity as Proxy
TargetNotAuditedEntity original = getEntityManager().find( TargetNotAuditedEntity.class, tnae1_id );
UnversionedStrTestEntity uste1 = getEntityManager().find( UnversionedStrTestEntity.class, uste1_id );
UnversionedStrTestEntity uste2 = getEntityManager().find( UnversionedStrTestEntity.class, uste2_id );
TargetNotAuditedEntity rev1 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 1 );
TargetNotAuditedEntity rev2 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 2 );
TargetNotAuditedEntity rev3 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 3 );
TargetNotAuditedEntity rev4 = getAuditReader().find( TargetNotAuditedEntity.class, tnae1_id, 4 );
assert rev1.getReference().equals( uste1 );
assert rev2.getReference().equals( uste2 );
assert rev3.getReference().equals( uste2 );
assert rev4.getReference().equals( uste1 );
assert original.getReference() instanceof HibernateProxy;
assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( original.getReference() ) );
assert UnversionedStrTestEntity.class.equals( HibernateProxyHelper.getClassWithoutInitializingProxy( rev1.getReference() ) );
assert UnversionedStrTestEntity.class.equals( Hibernate.getClass( rev1.getReference() ) );
}
代码示例来源:origin: openmrs/openmrs-core
Class<?> thisClass = Hibernate.getClass(this);
Class<?> objClass = Hibernate.getClass(obj);
if (!(thisClass.isAssignableFrom(objClass) || objClass.isAssignableFrom(thisClass))){
return false;
代码示例来源:origin: Exrick/x-boot
@SuppressWarnings({"rawtypes", "unchecked"})
@Override
public void write(JsonWriter out, HibernateProxy value) throws IOException {
if (value == null) {
out.nullValue();
return;
}
// Retrieve the original (not proxy) class
Class<?> baseType = Hibernate.getClass(value);
// Get the TypeAdapter of the original class, to delegate the serialization
TypeAdapter delegate = context.getAdapter(TypeToken.get(baseType));
// Get a filled instance of the original class
Object unproxiedValue = ((HibernateProxy) value).getHibernateLazyInitializer()
.getImplementation();
// Serialize the value
delegate.write(out, unproxiedValue);
}
}
代码示例来源:origin: hibernate/hibernate-search
@Override
// The actual class of a proxy of type T is always a Class<? extends T> (unless T is HibernateProxy, but we don't expect that)
@SuppressWarnings("unchecked")
public <T> Class<? extends T> getClass(T entity) {
return Hibernate.getClass( entity );
}
代码示例来源:origin: hibernate/hibernate-search
/**
* Get the real class type.
* In case of Hibernate proxies, return the entity type rather than the proxy's
*
* @param <T> the type of the entity
* @param entity an instance of the entity type
* @return the real class of the type
*/
public static <T> Class<T> getClass(T entity) {
return Hibernate.getClass( entity );
}
代码示例来源:origin: skyscreamer/yoga
@SuppressWarnings("unchecked")
public <T> Class<T> findClass( T instance )
{
return Hibernate.getClass( instance );
}
}
代码示例来源:origin: riotfamily/riot
/**
* Returns the true underlying class of a possibly proxied record.
* @see Hibernate#getClass(Object)
*/
public static Class<?> getClass(ActiveRecord a) {
return Hibernate.getClass(a);
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public boolean isWorkable(Object entity) {
return isWorkable( Hibernate.getClass( entity ) );
}
代码示例来源:origin: org.grails/grails-hibernate
@Override
protected GrailsDomainClass getAssociatedDomainClassFromApplication(Object associatedObject) {
String associatedObjectType = Hibernate.getClass(associatedObject).getName();
return (GrailsDomainClass) grailsApplication.getArtefact(DomainClassArtefactHandler.TYPE, associatedObjectType);
}
代码示例来源:origin: omero/server
/**
* Construct an instance corresponding to the given object.
* @param object a persisted object instance
*/
CI(IObject object) {
if (object instanceof HibernateProxy) {
this.className = Hibernate.getClass(object).getName();
} else {
this.className = object.getClass().getName();
}
this.id = object.getId();
}
代码示例来源:origin: skyscreamer/yoga
@Override
public <T> T find( Class<T> type, long id )
{
T entity = hibernateTemplate.load( type, id );
// Force exception if not found (Hibernate 3 defaults to lazy load.)
Hibernate.getClass( entity );
return entity;
}
代码示例来源:origin: hibernate/hibernate-search
@Override
public boolean equals(Object o) {
if ( this == o ) {
return true;
}
if ( o == null || getClass() != Hibernate.getClass( o ) ) {
return false;
}
AbstractEntity<?> other = (AbstractEntity<?>) o;
return Objects.equals( getId(), other.getId() );
}
代码示例来源:origin: riotfamily/riot
public static Serializable getId(SessionFactory sessionFactory, Object bean) {
Class<?> clazz = Hibernate.getClass(bean);
ClassMetadata metadata = sessionFactory.getClassMetadata(clazz);
return metadata.getIdentifier(bean, (SessionImplementor) sessionFactory.getCurrentSession());
}
代码示例来源:origin: riotfamily/riot
public SignaturePattern(String action, Object obj, Object context) {
this.action = StringUtils.uncapitalize(FormatUtils.xmlToCamelCase(action));
if (obj != null) {
objectClass = Hibernate.getClass(obj);
}
if (context != null) {
contextClass = context.getClass();
}
}
代码示例来源:origin: org.hibernate/com.springsource.org.hibernate.ejb
public Object getIdentifier(Object entity) {
final Class entityClass = Hibernate.getClass( entity );
final ClassMetadata classMetadata = emf.getSessionFactory().getClassMetadata( entityClass );
if (classMetadata == null) {
throw new IllegalArgumentException( entityClass + " is not an entity" );
}
//TODO does that work for @IdClass?
return classMetadata.getIdentifier( entity );
}
}
代码示例来源:origin: jpos/jPOS-EE
@SuppressWarnings("unchecked")
public static <T> T unwrap (T proxy) {
Hibernate.getClass(proxy);
Hibernate.initialize(proxy);
return (proxy instanceof HibernateProxy) ?
(T) ((HibernateProxy) proxy).getHibernateLazyInitializer().getImplementation() : proxy;
}
内容来源于网络,如有侵权,请联系作者删除!