Skip to content

Add methods in Metamodel interface to get entity by jpa name #85

Closed
@lukasj

Description

@lukasj

Hello guys,

following this one:

https://www.java.net/forum/topic/glassfish/glassfish/how-obtain-class-j
pa-entity-name

and this one:

https://hibernate.atlassian.net/browse/HHH-9217

let's say I define an entity like this:

@Entity(name = "car")
public class Car {
}

now I want to get the EntityType by the name value (by "car").
Unfortunately this seems to be impossible I can get hold of the
EntityManager and from there I can get the Metamodel interface, but in
there I can see only one method which accept a class object:

<X> EntityType<X> entity(Class<X> cls);

I would like to propose several new methods to be included:

<X> EntityType<X> entity(String jpaEntityName);

<X> ManagedType<X> managedType(String jpaEntityName);

<X> EmbeddableType<X> embeddable(String jpaEntityName);

It seems quite logical to get the entity by the name it was given
(otherwise what' really the purpose of this name). And, yes, I know
about the solution where you get all the entities and iterate in a loop
and compare their names with the one you have, but I guess you would
agree this is a really poor performancewise. Another plus to this is
that the underlying implementation would be super-easy: just keep the
jpaEntityNames in a map (even for hibernate I have provided a 1-line
patch).

Please let me know what you think.

Thanks, and keep up the good work.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions