Java Code Examples for javax.persistence.EntityManager#getMetamodel()

The following examples show how to use javax.persistence.EntityManager#getMetamodel() . 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: JPAPersistenceManager.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
public EntityType getTargetEntity(RegistryConfiguration registryConf, EntityManager entityManager) {

		EntityType targetEntity;

		String targetEntityName = getTargetEntityName(registryConf);

		Metamodel classMetadata = entityManager.getMetamodel();
		Iterator it = classMetadata.getEntities().iterator();

		targetEntity = null;
		while (it.hasNext()) {
			EntityType entity = (EntityType) it.next();
			String jpaEntityName = entity.getName();

			if (entity != null && jpaEntityName.equals(targetEntityName)) {
				targetEntity = entity;
				break;
			}
		}

		return targetEntity;
	}
 
Example 2
Source File: OrmCriteria.java    From sample-boot-micro with MIT License 5 votes vote down vote up
/** 指定したEntityクラスにエイリアスを紐付けたCriteriaを生成します。 */
private OrmCriteria(EntityManager em, Class<T> clazz, String alias) {
    this.clazz = clazz;
    this.metamodel = em.getMetamodel();
    this.builder = em.getCriteriaBuilder();
    this.query = builder.createQuery(clazz);
    this.root = query.from(clazz);
    this.alias = alias;
    this.root.alias(alias);
}
 
Example 3
Source File: OrmCriteria.java    From sample-boot-hibernate with MIT License 5 votes vote down vote up
/** 指定したEntityクラスにエイリアスを紐付けたCriteriaを生成します。 */
private OrmCriteria(EntityManager em, Class<T> clazz, String alias) {
    this.clazz = clazz;
    this.metamodel = em.getMetamodel();
    this.builder = em.getCriteriaBuilder();
    this.query = builder.createQuery(clazz);
    this.root = query.from(clazz);
    this.alias = alias;
    this.root.alias(alias);
}
 
Example 4
Source File: JtaEntityManager.java    From tomee with Apache License 2.0 5 votes vote down vote up
public Metamodel getMetamodel() {
    final EntityManager entityManager = getEntityManager();
    try {
        final Timer timer = Op.getMetamodel.start(this.timer, this);
        try {
            return entityManager.getMetamodel();
        } finally {
            timer.stop();
        }
    } finally {
        closeIfNoTx(entityManager);
    }
}
 
Example 5
Source File: AbstractModelService.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private <T> String getTableName(EntityManager em, Class<T> entityClass){
	/*
	 * Check if the specified class is present in the metamodel.
	 * Throws IllegalArgumentException if not.
	 */
	Metamodel meta = em.getMetamodel();
	EntityType<T> entityType = meta.entity(entityClass);
	
	//Check whether @Table annotation is present on the class.
	Table t = entityClass.getAnnotation(Table.class);
	
	String tableName = (t == null) ? entityType.getName().toUpperCase() : t.name();
	return tableName;
}
 
Example 6
Source File: CustomSpecifications.java    From spring-boot-rest-api-helpers with MIT License 4 votes vote down vote up
public Attribute getIdAttribute(EntityManager em, Class<T> clazz) {
    Metamodel m = em.getMetamodel();
    IdentifiableType<T> of = (IdentifiableType<T>) m.managedType(clazz);
    return of.getId(of.getIdType().getJavaType());
}