Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipselink-users] FW: [TopLink Essentials] @SqlResultSetMappingJOINed details are gettingignored

Chris,

 

thanks for your kind help.

 

I understand that we have to iterate over the result, clear the Master.details collection, and fill in all the details returned by the mapper. Is that correct? Sounds like this should work, while it is a nasty job. Ain't there a solution how we can tell TopLink that it shall not invoke the subsequent SQL but just accept the detail entities it just generated? As it has all that it knows to do the job, this should be possible. :-)

 

Another problem is preventing unwanted database changes. Is there a possibility to actively detach the Master from the persistence context before clearing ist Master.details collection? If not, how to prevent the EntityManager from removing the details on the database?

 

Thanks

Markus

 

From: eclipselink-users-bounces@xxxxxxxxxxx [mailto:eclipselink-users-bounces@xxxxxxxxxxx] On Behalf Of Christopher Delahunt
Sent: Donnerstag, 24. Juni 2010 15:07
To: EclipseLink User Discussions
Subject: Re: [eclipselink-users] FW: [TopLink Essentials] @SqlResultSetMappingJOINed details are gettingignored

 

The problem with custom SQL returning Entities are that they managed entities, and such that incomplete data built into an entity remains in the cache (or the full managed object returned if it is already in the cache).  Entities are not data objects that can be left incomplete.  What it seems like you need would be a JPQL constructor type query but for native SQL. 

The results from the query should still give the object pairs you requested, assuming you have set the query to return the Master and Detail objects from the join.  The application will need to process over the results to get all the Master->Detail pairings returned from the results, much like it would for rows when returning raw data. 

Best Regards,
Chris

On 24/06/2010 8:49 AM, Markus Karg wrote:

Today for the first time now I had to use @SqlResultSetMapping. While everything works well there so far, there still is one issue I would like to solve. Possibly you can help me. :-)

 

I am executing a typical master-detail JOIN:

 

SELECT Master.PK_A, Detail.PK_B FROM Master JOIN Detail ON (Master.PK_A = Detail.FK_A) WHERE Master.X = ? AND Detail.Y = ?

 

The result is exactly what I expected: A table containing all details having Y = ? and their corresponding masters.

 

But actually I want to get not fields but entity instances, so I added SqlResultSetMapping for Master and Detail, which both are annotated with @Entity, @Table, @Column, etc.

 

The result is not exactly what I want get…: The "AND Detail.Y = ?" has no effect on that details linked with each master.

 

When iterating over the Master.details collection which was automatically filled by TopLink behind the scenes thanks to the @OneToMany relationship, I notice that ALL the master's details are contained - not just those with actually "Detail.Y = ?" as expected. Looking at the SQL TopLink does, it is rather clear why: The linked details are not filled from just my SQL's ResultSet, but actually TopLink executes another (automatically created) SQL to get ALL details per Master.

 

This is not what I want.

 

How to tell TopLink that it shall populate the linked details of each master with just the rows found in MY OWN SQL but not execute an unfiltered one?

 

Thanks!

Markus



____________
Virus checked by G DATA AntiVirus
Version: AVA 21.1046 dated 24.06.2010
Virus news: www.antiviruslab.com

 


 
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users
  


____________
Virus checked by G DATA AntiVirus
Version: AVA 21.1046 dated 24.06.2010
Virus news: www.antiviruslab.com

Back to the top