users@glassfish.java.net

Re: Accessing ids instead of objects in JPA _at_ManyToMany relationships

From: <glassfish_at_javadesktop.org>
Date: Sun, 07 Mar 2010 13:54:33 PST

Thanks for letting me know.

As it happens, I think I just figured out the answer myself. What I need is an @ElementCollection of Basic types -- as in the second example on this page:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/2.0/ElementCollections

Even though the player_ids in my example reference player objects in another Entity table, I only need to treat them as basic objects (ids) most of the time when being referenced from the Game entity objects.

So I can redefine the @ManyToMany relationship between the Game and Player objects as the Games having an @ElementCollection of player_ids. That will prevent JPA from loading all those Player objects just so I can get at the ids. It also makes it much easier to process the player_ids when they are not properties of a bean. When I do need more information about the player, I can easily access it using the player_id I already have.

I haven't tried this yet, but it looks reasonably certain that this is the answer I was looking for.

Note: this is a JPA 2.0 solution only.
[Message sent by forum member 'tacitust' (tacitus_at_yahoo.com)]

http://forums.java.net/jive/thread.jspa?messageID=390534