Java Code Examples for org.hibernate.metadata.ClassMetadata#getEntityName()

The following examples show how to use org.hibernate.metadata.ClassMetadata#getEntityName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Printer.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * @param entity an actual entity object, not a proxy!
 */
public String toString(Object entity, EntityMode entityMode) throws HibernateException {

	// todo : this call will not work for anything other than pojos!
	ClassMetadata cm = factory.getClassMetadata( entity.getClass() );

	if ( cm==null ) return entity.getClass().getName();

	Map result = new HashMap();

	if ( cm.hasIdentifierProperty() ) {
		result.put(
			cm.getIdentifierPropertyName(),
			cm.getIdentifierType().toLoggableString( cm.getIdentifier( entity, entityMode ), factory )
		);
	}

	Type[] types = cm.getPropertyTypes();
	String[] names = cm.getPropertyNames();
	Object[] values = cm.getPropertyValues( entity, entityMode );
	for ( int i=0; i<types.length; i++ ) {
		if ( !names[i].startsWith("_") ) {
			String strValue = values[i]==LazyPropertyInitializer.UNFETCHED_PROPERTY ?
				values[i].toString() :
				types[i].toLoggableString( values[i], factory );
			result.put( names[i], strValue );
		}
	}
	return cm.getEntityName() + result.toString();
}
 
Example 2
Source File: BasicHibernateDao.java    From base-framework with Apache License 2.0 2 votes vote down vote up
/**
 * 获取实体名称
 * 
 * @return String
 */
public String getEntityName() {
	ClassMetadata meta = sessionFactory.getClassMetadata(entityClass);
	return meta.getEntityName();
}