本文整理汇总了Java中org.hibernate.metadata.ClassMetadata.getEntityName方法的典型用法代码示例。如果您正苦于以下问题:Java ClassMetadata.getEntityName方法的具体用法?Java ClassMetadata.getEntityName怎么用?Java ClassMetadata.getEntityName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.metadata.ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata.getEntityName方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final Session session = getSession();
try {
System.out.println("querying all the managed entities...");
final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
for (Object key : metadataMap.keySet()) {
final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
final String entityName = classMetadata.getEntityName();
final Query query = session.createQuery("from " + entityName);
System.out.println("executing: " + query.getQueryString());
for (Object o : query.list()) {
System.out.println(" " + o);
}
}
} finally {
session.close();
}
}
示例2: main
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
final Session session = getSession();
try {
System.out.println("querying all the managed entity...");
final Map metadataMap = session.getSessionFactory().getAllClassMetadata();
for (Object key : metadataMap.keySet()) {
final ClassMetadata classMetadata = (ClassMetadata) metadataMap.get(key);
final String entityName = classMetadata.getEntityName();
for (Object o : getQuery("from " + entityName)) {
System.out.println(" " + o);
}
// for (Object o : getData(entityName)) {
// System.out.println(" " + o);
// }
}
} finally {
session.close();
}
}
示例3: getClassMetadata
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
private ClassMetadata getClassMetadata(String entityName) {
Map<String,ClassMetadata> classMetadatas=sessionFactory.getAllClassMetadata();
ClassMetadata classMetadata=null;
for(String fqcn:classMetadatas.keySet()) {
if (fqcn.endsWith("."+entityName) || (fqcn.equals(entityName))) {
if (classMetadata!=null) {
throw new RuntimeException("Existen 2 entidades con el mismo nombre:"+ fqcn + " y " + classMetadata.getEntityName() + " para la solicitud de " + entityName);
}
classMetadata=classMetadatas.get(fqcn);
}
}
return classMetadata;
}
示例4: deleteByMap
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 根据HaloMap删除
*
* @param parameter
* @return 返回行数 失败返回-1
*/
public final int deleteByMap(HaloMap parameter) {
if(null==parameter){
parameter= new HaloMap();
}
ClassMetadata cm = sessionFactory.getClassMetadata(this.entityType);
String entityName = cm.getEntityName();
String selectHql = String.format("delete %s ", entityName);
HqlWithParameter hqlWithParameter = createQueryHql(parameter, selectHql);
String hql = hqlWithParameter.getHql();
HaloMap hqlPrmMap = hqlWithParameter.getParamterMap();
if (hqlPrmMap.isEmpty()) {
logger.warn("不允许无条件删除!防止全表更新(可通过条件实现)");
return -1;
}
Query query = createQuery(hql, hqlPrmMap);
return query.executeUpdate();
}
示例5: printAllData
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Print all data that is held in this database
*
* @throws org.hibernate.HibernateException
*/
public static void printAllData() throws HibernateException {
Session session = getSession();
try {
System.out.println("querying all the managed entities...");
final Map<String, ClassMetadata> metadataMap = session.getSessionFactory().getAllClassMetadata();
for (String key : metadataMap.keySet()) {
final ClassMetadata classMetadata = metadataMap.get(key);
final String entityName = classMetadata.getEntityName();
final Query query = session.createQuery("from " + entityName);
System.out.println("executing: " + query.getQueryString());
for (Object o : query.list()) {
System.out.println(" " + o);
}
}
} finally {
session.close();
}
}
示例6: toString
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* @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();
}
示例7: findForeignKey
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* Find a foreign key matching the given property, by looking in the fkMap.
* The property may be defined on the class or a superclass, so this function calls itself recursively.
* @param propName Name of the property e.g. "Product"
* @param meta Class metadata, for traversing the class hierarchy
* @return The name of the foreign key, e.g. "ProductID"
*/
private String findForeignKey(String propName, ClassMetadata meta) {
String relKey = meta.getEntityName() + '.' + propName;
if (fkMap.containsKey(relKey)) {
return fkMap.get(relKey);
} else if (meta.isInherited() && meta instanceof AbstractEntityPersister) {
String superEntityName = ((AbstractEntityPersister) meta).getMappedSuperclass();
ClassMetadata superMeta = sessionFactory.getClassMetadata(superEntityName);
return findForeignKey(propName, superMeta);
} else {
throw new IllegalArgumentException("Foreign Key '" + relKey + "' could not be found.");
}
}
示例8: initMetadata
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/** Renseigne l'attribut _metadataList. */
protected void initMetadata() {
this.metadataList = new ArrayList<Metadata>();
Map<?, ?> allClassesMetadata = HibernateUtil.getSessionFactory().getAllClassMetadata();
for (Object key : allClassesMetadata.keySet()) {
if (GeodatabaseHibernate.logger.isDebugEnabled()) {
GeodatabaseHibernate.logger.debug("key = " + key);
}
ClassMetadata classMetadata = (ClassMetadata) allClassesMetadata.get(key);
if (GeodatabaseHibernate.logger.isDebugEnabled()) {
GeodatabaseHibernate.logger.debug("metadata = " + classMetadata);
}
String className = (classMetadata.getEntityName());
if (GeodatabaseHibernate.logger.isDebugEnabled()) {
GeodatabaseHibernate.logger.debug("entity name = " + className);
}
Metadata metadataElt = new Metadata();
metadataElt.setClassName(className);
String[] propertyNames = classMetadata.getPropertyNames();
if (GeodatabaseHibernate.logger.isDebugEnabled()) {
for (int i = 0; i < propertyNames.length; i++) {
GeodatabaseHibernate.logger.debug("property name " + i + " = " + propertyNames[i]);
}
}
if (classMetadata instanceof AbstractEntityPersister) {
metadataElt.setTableName(((AbstractEntityPersister) classMetadata).getRootTableName());
metadataElt.setIdFieldName(((AbstractEntityPersister) classMetadata).getIdentifierPropertyName());
metadataElt.setIdColumnName(((AbstractEntityPersister) classMetadata).getIdentifierColumnNames()[0]);
// FIXME a revoir: aussi l'enveloppe, les srid, la dimension, et
// d'autres...
metadataElt.setGeomColumnName("geom");
if (GeodatabaseHibernate.logger.isDebugEnabled()) {
GeodatabaseHibernate.logger.debug("table name = " + metadataElt.getTableName());
GeodatabaseHibernate.logger.debug("id field name = " + metadataElt.getIdFieldName());
GeodatabaseHibernate.logger.debug("id column name = " + metadataElt.getIdColumnName());
}
}
this.metadataList.add(metadataElt);
}
}
示例9: getEntityClassName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 获取实体类型名
* @author FengJianBo
* @return
* 2014年3月18日 下午2:33:01
*/
protected String getEntityClassName() {
ClassMetadata meta = sessionFactory.getCurrentSession().getSessionFactory().getClassMetadata(getEntityClass());
return meta.getEntityName();
}
示例10: getEntityName
import org.hibernate.metadata.ClassMetadata; //导入方法依赖的package包/类
/**
* 获取实体名称
*
* @return String
*/
public String getEntityName() {
ClassMetadata meta = sessionFactory.getClassMetadata(entityClass);
return meta.getEntityName();
}