本文整理了Java中org.hibernate.SessionFactory.getClassMetadata()
方法的一些代码示例,展示了SessionFactory.getClassMetadata()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SessionFactory.getClassMetadata()
方法的具体详情如下:
包路径:org.hibernate.SessionFactory
类名称:SessionFactory
方法名:getClassMetadata
[英]Retrieve the ClassMetadata associated with the given entity class.
[中]检索与给定实体类关联的类元数据。
代码示例来源:origin: hibernate/hibernate-orm
private boolean copyState(Object entity, Type[] types, Object[] state, SessionFactory sf) {
// copy the entity state into the state array and return true if the state has changed
ClassMetadata metadata = sf.getClassMetadata( entity.getClass() );
Object[] newState = metadata.getPropertyValues( entity );
int size = newState.length;
boolean isDirty = false;
for ( int index = 0; index < size; index++ ) {
if ( ( state[index] == LazyPropertyInitializer.UNFETCHED_PROPERTY &&
newState[index] != LazyPropertyInitializer.UNFETCHED_PROPERTY ) ||
( state[index] != newState[index] && !types[index].isEqual( state[index], newState[index] ) ) ) {
isDirty = true;
state[index] = newState[index];
}
}
return isDirty;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Field getIdField(Class<?> clazz, Session session) {
clazz = getNonProxyImplementationClassIfNecessary(clazz);
ClassMetadata metadata = session.getSessionFactory().getClassMetadata(clazz);
Field idField = ReflectionUtils.findField(clazz, metadata.getIdentifierPropertyName());
idField.setAccessible(true);
return idField;
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<String> getPropertyNames(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<String> propertyNames = new ArrayList<>();
Collections.addAll(propertyNames, metadata.getPropertyNames());
return propertyNames;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public List<Type> getPropertyTypes(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
ClassMetadata metadata = getSessionFactory(entityManager).getClassMetadata(entityClass);
List<Type> propertyTypes = new ArrayList<>();
Collections.addAll(propertyTypes, metadata.getPropertyTypes());
return propertyTypes;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Field getIdField(Class<?> clazz, EntityManager em) {
clazz = getNonProxyImplementationClassIfNecessary(clazz);
ClassMetadata metadata = em.unwrap(Session.class).getSessionFactory().getClassMetadata(clazz);
Field idField = ReflectionUtils.findField(clazz, metadata.getIdentifierPropertyName());
idField.setAccessible(true);
return idField;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
@Override
public Map<String, Object> getIdMetadata(Class<?> entityClass, HibernateEntityManager entityManager) {
entityClass = getNonProxyImplementationClassIfNecessary(entityClass);
Map<String, Object> response = new HashMap<>();
SessionFactory sessionFactory = entityManager.getSession().getSessionFactory();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata == null) {
return null;
}
String idProperty = metadata.getIdentifierPropertyName();
response.put("name", idProperty);
Type idType = metadata.getIdentifierType();
response.put("type", idType);
return response;
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
/**
*
* @param em
* @param entityType
* @param ids
*/
public static void executeTargetedCacheInvalidation(EntityManager em, Class<?> entityType, List<Long> ids) {
Session session = em.unwrap(Session.class);
for (Long id : ids) {
session.getSessionFactory().getCache().evictEntity(entityType, id);
}
//update the timestamp cache for the table so that queries will be refreshed
ClassMetadata metadata = session.getSessionFactory().getClassMetadata(entityType);
String tableName = ((AbstractEntityPersister) metadata).getTableName();
UpdateTimestampsCache timestampsCache = em.unwrap(SessionImplementor.class).getFactory().getUpdateTimestampsCache();
if (timestampsCache != null) {
timestampsCache.invalidate(new Serializable[]{tableName});
}
}
代码示例来源:origin: BroadleafCommerce/BroadleafCommerce
Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao().
getAllPolymorphicEntitiesFromCeiling(addMetadataFromFieldTypeRequest.getType().getReturnedClass());
foreignMetadata = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getSessionFactory().getClassMetadata(entities
[entities.length - 1]);
foreignKeyClass = entities[entities.length - 1].getName();
try {
foreignMetadata = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getSessionFactory().
getClassMetadata(Class.forName(addMetadataFromFieldTypeRequest.getForeignField()
.getForeignKeyClass()));
foreignKeyClass = addMetadataFromFieldTypeRequest.getForeignField().getForeignKeyClass();
(addMetadataFromFieldTypeRequest.getType().getReturnedClass());
foreignMetadata = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getSessionFactory().
getClassMetadata(entities[entities.length - 1]);
foreignKeyClass = entities[entities.length - 1].getName();
lookupDisplayProperty = ((BasicFieldMetadata) addMetadataFromFieldTypeRequest.getPresentationAttribute()).
try {
foreignMetadata = addMetadataFromFieldTypeRequest.getDynamicEntityDao().getSessionFactory().
getClassMetadata(Class.forName(addMetadataFromFieldTypeRequest.getAdditionalForeignFields()
[addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition()].getForeignKeyClass()));
foreignKeyClass = addMetadataFromFieldTypeRequest.getAdditionalForeignFields()[
代码示例来源:origin: my2iu/Jinq
public MetamodelUtilFromSessionFactory(SessionFactory factory)
{
// Go through all the entities
for (String entityClassName: factory.getAllClassMetadata().keySet())
{
ClassMetadata entityData = factory.getClassMetadata(entityClassName);
classToEntityName.put(entityData.getMappedClass(), entityData.getEntityName());
classNameToEntityName.put(entityClassName, entityData.getEntityName());
//System.out.println(entityClassName + " " + entityData.getMappedClass().getCanonicalName() + " " + entityData.getEntityName());
// TODO: It turns out all three values are the same, but I think it's ok for now.
scanClassMetadata(entityData);
}
}
代码示例来源:origin: openmrs/openmrs-core
AbstractEntityPersister aep = (AbstractEntityPersister) sessionFactory.getClassMetadata(Patient.class);
String[] properties = aep.getPropertyColumnNames(attribute);
if (properties.length >= 1) {
AbstractEntityPersister aep = (AbstractEntityPersister) sessionFactory.getClassMetadata(Person.class);
if (aep != null) {
String[] properties = aep.getPropertyColumnNames(attribute);
.getClassMetadata(PersonName.class);
if (aep != null) {
String[] properties = aep.getPropertyColumnNames(attribute);
.getClassMetadata(PatientIdentifier.class);
if (aep != null) {
代码示例来源:origin: openmrs/openmrs-core
String idPropertyName = getSession().getSessionFactory().getClassMetadata(getType()).getIdentifierPropertyName();
代码示例来源:origin: openmrs/openmrs-core
public void validate(Object object, Errors errors) throws DAOException {
Class entityClass = object.getClass();
ClassMetadata metadata = sessionFactory.getClassMetadata(entityClass);
if (metadata != null) {
String[] propNames = metadata.getPropertyNames();
代码示例来源:origin: com.github.dactiv/dactiv-orm
/**
* 取得对象的主键名.
*
* @return String
*/
public String getIdName() {
ClassMetadata meta = sessionFactory.getClassMetadata(entityClass);
return meta.getIdentifierPropertyName();
}
代码示例来源:origin: org.jboss.ejb3/jboss-ejb3-jpa-int
@SuppressWarnings("unchecked")
public ClassMetadata getClassMetadata(Class persistentClass) throws HibernateException
{
return getSessionFactory().getClassMetadata(persistentClass);
}
代码示例来源:origin: ldlqdsdcn/eidea4
public Metadata get(Class<?> entityClass) throws IllegalArgumentException {
entityClass = getUnproxiedClass(entityClass);
ClassMetadata cm = sessionFactory.getClassMetadata(entityClass);
if (cm == null) {
throw new IllegalArgumentException("Unable to introspect " + entityClass.toString()
+ ". The class is not a registered Hibernate entity.");
} else {
return new HibernateEntityMetadata(sessionFactory, cm, null);
}
}
代码示例来源:origin: ro.fortsoft/generic-data-dao
private <T> void checkHibernateMapping(final Class<T> clazz) {
if (getSessionFactory().getClassMetadata(clazz) == null) {
throw new HibernateMappingException("Hibernate mapping fault. Check to see if " + clazz.getName()
+ " was mapped in the persistence context");
}
}
代码示例来源:origin: org.sakaiproject.genericdao/generic-dao
public String getIdProperty(Class<?> entityClass) {
ClassMetadata classmeta = getSessionFactory().getClassMetadata(entityClass);
if (classmeta == null) return null;
return classmeta.getIdentifierPropertyName();
}
代码示例来源:origin: com.pojosontheweb/woko-hibernate
public Class<?> getPrimaryKeyClass(Class<?> entityClass) {
ClassMetadata cm = sessionFactory.getClassMetadata(entityClass);
if (cm == null) {
// default to String
return String.class;
} else {
return cm.getIdentifierType().getReturnedClass();
}
}
代码示例来源:origin: hibernate/hibernate
protected void bindParameters(SessionImplementor session, PreparedStatement ps, Object object, PostInsertIdentityPersister persister)
throws SQLException {
Type uniqueKeyPropertyType = session.getSessionFactory()
.getClassMetadata(entityName)
.getPropertyType(uniqueKeyPropertyName);
Object uniqueKeyValue = persister.getPropertyValue( object, uniqueKeyPropertyName, session.getEntityMode() );
uniqueKeyPropertyType.nullSafeSet( ps, uniqueKeyValue, 1, session );
}
代码示例来源:origin: org.jboss.seam/jboss-seam
@Override
protected String getEntityName()
{
try
{
return getSession().getEntityName(getInstance());
}
catch (TransientObjectException e)
{
return getSession().getSessionFactory().getClassMetadata(getInstance().getClass()).getEntityName();
}
}
内容来源于网络,如有侵权,请联系作者删除!