users@glassfish.java.net

RE: How to obtain Class from JPA entity name?

From: Martin Gainty <mgainty_at_hotmail.com>
Date: Wed, 11 May 2011 13:34:24 -0400

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

for (Type.PersistenceType c : em.getEntityManagerFactory().getMetaModel().getEntities().getIDType().getPersisentType().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! :-) RegardsMarkus