users@glassfish.java.net

Re: JPA - One-To-Many relationship query problem

From: <glassfish_at_javadesktop.org>
Date: Fri, 01 Feb 2008 13:07:56 PST

Thanks Gordon.

Well, I do know the reason for the cardinality issue. Unfortunately, there is a fixed set of types of changes I can make to the legacy system DB model. Creating a new join table is more acceptable than adding a new ID attribute. So I will stick with the second approach.

I went through the documentation and such and figured out that one-to-many relationships are loaded lazy by default. But the point was the lazy loading didnt seem to work. Though the code snippet I posted doesnt show the code that accesses the collection, I do access it and translate it to a format that the client expects it in. But it just wouldnt work. When you say "You will simply need to access the relationship's collection", I am assuming, I just need to access the collection using the getter method. And I am accessing the collection, well within the scope of the same transaction, the list would always come up as empty. May be its a defect with the toplink implementation, unless there is something special I need to do to access this collection.

I figured out the problem with inserts. It was a stupid bug in my implementation of building the list.

Thanks a lot for the quick responses and suggestion. It is really appreciated.
[Message sent by forum member 'pmysore' (pmysore)]

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