users@glassfish.java.net

RE: How to obtain Class from JPA entity name?

From: Markus KARG <markus_at_headcrashing.eu>
Date: Wed, 11 May 2011 20:56:09 +0200

Great, that looks really promising! Never heard of "getMetaModel" before,
but sounds like what I need! :-)

 

Thank you very much, this really helps!

Markus

 

From: Martin Gainty [mailto:mgainty_at_hotmail.com]
Sent: Mittwoch, 11. Mai 2011 19:34
To: users_at_glassfish.java.net
Subject: RE: How to obtain Class from JPA entity name?

 

//assuming you have access to the EntityManager?
java.persistence.EntityManager em;
    

for (Type.PersistenceType c :
em.getEntityManagerFactory().getMetaModel().getEntities().getIDType().getPer
sisentType().values())
   if(c.equalsIgnoreCase("ENTITY") return c.getDeclaringClass().toString();

http://download.oracle.com/javaee/6/api/javax/persistence/EntityManager.html

does this help?
Martin
______________________________________________
Verzicht und Vertraulichkeitanmerkung

 
Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene
Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte
Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht
dient lediglich dem Austausch von Informationen und entfaltet keine
rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von
E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.

 







  _____

Subject: How to obtain Class from JPA entity name?
Date: Wed, 11 May 2011 17:19:59 +0200
From: karg_at_quipsy.de
To: users_at_glassfish.java.net

Is there any chance for a program running in GlassFish to find out the
java.lang.Class that is the one having @Entity(name = "X")?

 

In other words, a users types in the String "X" and what he shall get is the
java.lang.Class that has @Entity(name = "X") or is class X and just has
@Entity.

 

I have no idea to solve that, but all the info is found at runtime
somewhere, so there should be a way to do that.

 

Thanks for all ideas! :-)

 

Regards

Markus