Entities are added to metamodel with their classname instead of with the name parameter of the @Entity annotation

Description

Hi guys,

I want to get an entity from the metamodel based on it's name. My entity is the following:

@Cacheable @Entity(name = CategoryModel.NAME) @Table(name = CategoryModel.NAME, uniqueConstraints = { @UniqueConstraint(columnNames = { "pk", "id" }) }, indexes = { @Index(columnList = "id")}) public class CategoryModel extends AbstractEntityModel { public static final String NAME = "category"; }

so I use:

EntityType<T> type = ((MetamodelImpl) metamodel).getEntityTypeByName("category");

but this returns null. So I examined what is being added in the metamodel and here (EntityBinder:bindEntity:246):

persistentClass.setEntityName( annotatedClass.getName() );

looks like you are always using the classname of the entity, and not the name parameter of the @Entity annotation. This means that I can never get the entity by it's name.

Activity

Brett MeyerApril 22, 2015 at 9:14 PM

Closing rejected issues.

Former userJuly 24, 2014 at 7:31 PM

Hi Petar Tahchiev,

org.hibernate.jpa.internal.metamodel.MetamodelImp is Hibernate's internal implementation of javax.persistence.metamodel.Metamodel, which only provides a lookup by entity class. Applications should only rely on the API defined by javax.persistence.metamodel.Metamodel.

Petar TahchievJuly 24, 2014 at 6:13 PM
Edited

Hi ,

I do understand your point of view. But please, can you answer this: PersistentClass has several properties: entityName, className, jpaEntityName. At the moment entityName and className both hold the class name. I think one of them must be redundant. So the jpaEntityName holds the entity name that I'm interested in (the @Entity(name="myEntity")). However you can never access it so I believe this is redundant too. Maybe it does require a lot of refactoring or introducing a new method getEntityByJpaName but I don't agree that this feature is invalid. Otherwise how can we get an entity by it's jpa name? Please let me know what you think.

Former userJuly 24, 2014 at 12:14 AM

org.hibernate.jpa.internal.metamodel.MetamodelImpl is only intended to be used internally by Hibernate and should not be used by applications. There is internal code that assumes that the mapping is by entity name, not JPA entity name.

Petar TahchievJune 5, 2014 at 12:18 PM

Rejected

Details

Assignee

Reporter

Priority

Created May 24, 2014 at 11:45 AM
Updated April 22, 2015 at 9:14 PM
Resolved July 24, 2014 at 12:14 AM

Flag notifications