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

The following are Jave code examples for showing how to use getEntityName() of the org.hibernate.metadata.ClassMetadata class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: ssh   File: Main.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 2
Project: lucas   File: DBConnectionUtil.java   View Source Code Vote up 6 votes
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();
        }
    }
 
Example 3
Project: First-Dash-Service   File: Main.java   View Source Code Vote up 6 votes
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();
    }
}
 
Example 4
Project: ix3   File: MetaDataFactoryImplHibernate.java   View Source Code Vote up 6 votes
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;
}
 
Example 5
Project: haloDao-Hibernate3   File: HaloDao.java   View Source Code Vote up 6 votes
/**
 * 根据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();
}
 
Example 6
Project: brewninja   File: HibernateUtil.java   View Source Code Vote up 6 votes
/**
 * 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();
	}
}
 
Example 7
Project: cacheonix-core   File: Printer.java   View Source Code Vote up 5 votes
/**
 * @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 8
Project: breeze.server.java   File: RelationshipFixer.java   View Source Code Vote up 5 votes
/**
 * 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.");
    }
}
 
Example 9
Project: geoxygene   File: GeodatabaseHibernate.java   View Source Code Vote up 4 votes
/** 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);
	}
}
 
Example 10
Project: shj_template   File: BaseDaoImpl.java   View Source Code Vote up 2 votes
/**
 * 获取实体类型名
 * @author FengJianBo
 * @return
 * 2014年3月18日 下午2:33:01
 */
protected String getEntityClassName() {
	ClassMetadata meta = sessionFactory.getCurrentSession().getSessionFactory().getClassMetadata(getEntityClass());
	return meta.getEntityName();
}
 
Example 11
Project: base-framework   File: BasicHibernateDao.java   View Source Code Vote up 2 votes
/**
 * 获取实体名称
 * 
 * @return String
 */
public String getEntityName() {
	ClassMetadata meta = sessionFactory.getClassMetadata(entityClass);
	return meta.getEntityName();
}