Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lukasj opened this issue Jul 28, 2014 · 6 comments · Fixed by #448
Closed

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

lukasj opened this issue Jul 28, 2014 · 6 comments · Fixed by #448

Comments

@lukasj
Copy link
Contributor

lukasj commented Jul 28, 2014

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.

@lukasj
Copy link
Contributor Author

lukasj commented Jul 28, 2014

@glassfishrobot Commented
Reported by paranoiabla

@lukasj
Copy link
Contributor Author

lukasj commented Oct 28, 2016

@glassfishrobot Commented
neilstockton said:
The clear problem with those methods (not arguing against the usefulness) is that your generic "X" is undefined. The existing methods with a class define the X, yet when you have no class and instead a String then the user would have to spend their time casting

@lukasj
Copy link
Contributor Author

lukasj commented May 5, 2017

@glassfishrobot Commented
This issue was imported from java.net JIRA JPA_SPEC-85

@lukasj
Copy link
Contributor Author

lukasj commented Apr 4, 2018

@ptahchiev Commented
+1 on this

@lukasj
Copy link
Contributor Author

lukasj commented Aug 31, 2018

@gavinking
Copy link
Contributor

Solution proposed in #448.

@gavinking gavinking linked a pull request Aug 10, 2023 that will close this issue
lukasj pushed a commit that referenced this issue Aug 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants