Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Not retreiving OneToMany collections with lazy and eager option

Hello Kiran,

Look at your code and find where you populate an Application entity's appRejectMaps collection with ApplicationRejectMap entities.  If you are not doing it, the collection will always be empty (until a refresh).  Where ever you set the
ApplicationRejectMap -> Application  reference, you should also set the Application -> ApplicationRejectMap

Here is a quick example I found:

Best Regards,

On 22/11/2010 9:33 AM, Kiran Kumar Gubbi wrote:
Hi Christopher,

Sorry to bother you again. I am still not clear, may be an example will help
me to understand or if you can mention the changes do I need to make this
bidirectional mapping to work.


christopher delahunt wrote:
Sorry I was not clearer. 

No, there is nothing wrong with your mappings.  This is a reoccurring 
problem with bidirectional relationships, as JPA does not maintain 
relationships for you - the application must maintain both sides 
itself.  When the application sets applicationRejectMap.application = 
app, it must also add the applicationRejectMap to the app's 
appRejectMaps collection, otherwise each and every time you access the 
appRejectMaps it will never see this change - until you the app instance 
is refreshed. 

Best Regards,

On 22/11/2010 9:16 AM, Kiran Kumar Gubbi wrote:
Hi Christopher,

Here is my code.

The Application is parent entity which has collection OneToMany of
ApplicationRejectMap.  The entity detail given below.

@Table( name = "APPLICATION_TBL" )
public class Application {

@Column( name = "APPLICATION_ID", nullable = false, unique = true )
private Integer id;

@OneToMany( mappedBy = "application", fetch = FetchType.LAZY )
private Set< ApplicationRejectMap >  appRejectMaps;

The child class ApplicationRejectMap details which as ManyToOne relation
with Application as mentioned beow.

public class ApplicationRejectMap {

@Column( name = "REJECT_MAP_ID" )
private Integer id;

@JoinColumn( name = "REJECT_APPLICATION" )
private Application application;

Do you think is there any issue on this? 


christopher delahunt wrote:
Hello Kiran,

 From the sounds of it, the OneToMany is mapped by a OneToOne back 
pointer, and are maintaining relationship changes through the OneToOne 
but not the OneToMany.   If you set one side of a bi directional 
relationship, the application must also maintain the other side as well 
or the cache becomes out of synch with what is in the database until a 
refresh occurs.  Invalidating the objects is essentially forcing a 
refresh, which causes the OneToMany to be queried from the database. 

When you add/remove from a relationship, the application will also need 
to add/remove from the OneToMany collection as well.

Best Regards,

On 22/11/2010 6:01 AM, Kiran Kumar Gubbi wrote:
Hi all,

I am currently trying to improve performance of our application . One
thing I wanted to use is lazy loading of oneToMany collections. But it
like the data is not retrieved eventhough it is present in the
scenario is we upload the application form through web service, it
the form  data and if the form is not valid it generates rejection list
the database. On looking for this same form on our web application the
rejection list is not retrieved from the database. I have used fetch
lazy for this collection. One thing we have noticed that after clearing
cache using the following code from the screen the rejection list start
appearing on the screen.
( ( JpaEntityManager ) getEntityManager().getDelegate()
).getServerSession(). getIdentityMapAccessor().invalidateAll(); 

Is there something I am missing here ?

My colleague observed even Eager fetching is not working .



eclipselink-users mailing list

eclipselink-users mailing list


Back to the top