Re: persistence Digest 2 Mar 2010 21:57:16 -0000 Issue 870

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: persistence Digest 2 Mar 2010 21:57:16 -0000 Issue 870

Gary Jacobson
Hi Doug

I am injecting the EntityManager into my session beans as follows:

    @PersistenceContext
    protected EntityManager em;

I could inject the factory if that will make things easier.

Gary



---------- Forwarded message ----------
From: Douglas Clarke <[hidden email]>
To: [hidden email]
Date: Mon, 1 Mar 2010 04:15:35 -0800 (PST)
Subject: RE: List of entity classes
Gary,
 
TopLink Essentials has its own native metamodel you can use as well. Do you have access to an EntityManagerFactory in your usage or just managed EntityManager instances?
 
Doug
-----Original Message-----
From: Gary Jacobson [mailto:[hidden email]]
Sent: March 1, 2010 3:52 AM
To: [hidden email]
Subject: Re: List of entity classes

Thanks Doug

Unfortunately I am stuck with Toplink Essentials 2.0... do you know of any equivalent class/method I could use?

---------- Forwarded message ----------
From: Douglas Clarke <[hidden email]>
To: [hidden email]
Date: Thu, 25 Feb 2010 04:24:22 -0800 (PST)
Subject: RE: List of entity classes
If you are using the latest JPA 2.0 version of EclipseLink you can use:
 
EntityManagerFactory.getMetamodel();
 
Doug
-----Original Message-----
From: Gary Jacobson [mailto:[hidden email]]
Sent: February 25, 2010 7:00 AM
To: [hidden email]
Subject: List of entity classes

Hi all

Is there any way to retrieve a list of the entity classes available in the application? (i.e. any class with @Entity annotated)

The only way I can think to do this is to use native SQL to get a list of all database table names, convert them to class names by using my naming convention, and loading each class via reflection.

I would guess that there must be some internal toplink utility class which maintains a list.

Thanks
Gary




Reply | Threaded
Open this post in threaded view
|

RE: persistence Digest 2 Mar 2010 21:57:16 -0000 Issue 870

djclarke
Gary,
 
To access the underlying metamodel (Project -* Descriptor -* Mapping) you need to cast and un-wrap the native EntityManagerImpl. In container managed the container will provide its own wrapper so you will need to call getDelegate and cast the result.
 
((oracle.toplink.essentials.internal.ejb.cmp3.base.EntityManagerImpl) em.getDelegate()).getServerSession().getProject();
 
The project has a map of descriptors keyed by entity class.
 
The only wrinkle in this is that getDelegate() will return null if you are not within a transaction.
 
Doug
-----Original Message-----
From: Gary Jacobson [mailto:[hidden email]]
Sent: March 3, 2010 5:45 AM
To: [hidden email]
Subject: Re: persistence Digest 2 Mar 2010 21:57:16 -0000 Issue 870

Hi Doug

I am injecting the EntityManager into my session beans as follows:

    @PersistenceContext
    protected EntityManager em;

I could inject the factory if that will make things easier.

Gary



---------- Forwarded message ----------
From: Douglas Clarke <[hidden email]>
To: [hidden email]
Date: Mon, 1 Mar 2010 04:15:35 -0800 (PST)
Subject: RE: List of entity classes
Gary,
 
TopLink Essentials has its own native metamodel you can use as well. Do you have access to an EntityManagerFactory in your usage or just managed EntityManager instances?
 
Doug
-----Original Message-----
From: Gary Jacobson [mailto:[hidden email]]
Sent: March 1, 2010 3:52 AM
To: [hidden email]
Subject: Re: List of entity classes

Thanks Doug

Unfortunately I am stuck with Toplink Essentials 2.0... do you know of any equivalent class/method I could use?

---------- Forwarded message ----------
From: Douglas Clarke <[hidden email]>
To: [hidden email]
Date: Thu, 25 Feb 2010 04:24:22 -0800 (PST)
Subject: RE: List of entity classes
If you are using the latest JPA 2.0 version of EclipseLink you can use:
 
EntityManagerFactory.getMetamodel();
 
Doug
-----Original Message-----
From: Gary Jacobson [mailto:[hidden email]]
Sent: February 25, 2010 7:00 AM
To: [hidden email]
Subject: List of entity classes

Hi all

Is there any way to retrieve a list of the entity classes available in the application? (i.e. any class with @Entity annotated)

The only way I can think to do this is to use native SQL to get a list of all database table names, convert them to class names by using my naming convention, and loading each class via reflection.

I would guess that there must be some internal toplink utility class which maintains a list.

Thanks
Gary