Issue Details (XML | Word | Printable)

Key: OPENJPA-313
Type: Bug Bug
Status: Resolved Resolved
Resolution: Fixed
Priority: Major Major
Assignee: Unassigned
Reporter: Catalina Wei
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
OpenJPA

list of objects returned by query partially correct

Created: 10/Aug/07 11:14 PM   Updated: 16/Aug/07 02:49 PM
Return to search
Component/s: jdbc
Affects Version/s: None
Fix Version/s: 1.0.0

Time Tracking:
Not Specified

File Attachments:
  Size
Text File Licensed for inclusion in ASF works jpa1.0.0.patch 2007-08-10 11:34 PM Catalina Wei 2 kB
Text File Licensed for inclusion in ASF works OPENJPA-313.2.patch 2007-08-15 02:23 AM Catalina Wei 3 kB
Text File Licensed for inclusion in ASF works OPENJPA-313.r564688.patch 2007-08-14 04:27 AM Catalina Wei 2 kB
Text File Licensed for inclusion in ASF works OPENJPA-313.r564688.patch 2007-08-11 02:53 AM Catalina Wei 2 kB

Resolution Date: 16/Aug/07 02:49 PM


 Description  « Hide
We have an object inheritance hierarchy as follows.

    FixedAnnuity extends Annuity
    EquityAnnuity extends Annuity

Then we have following code:

    List<IAnnuity> annuities = getServerAdapter().findHolderAnnuities(holder);

from which we expect to have a list of "Annuity" (could be Annuity, FixedAnnuity or
EquityAnnuity) from following code
EntityManager em = null;
try{
em = factory.createEntityManager();
Query query = em.createNamedQuery("GetHolderAnnuities");
query.setParameter("holderId", holder.getId());
return (List<IAnnuity>) query.getResultList();
}

Here is the query
<named-query name="GetHolderAnnuities">
<query>SELECT a FROM Annuity AS a WHERE a.annuityHolderId = :holderId</query>
</named-query>

In the end, the list returned only the first object with the correct Object, the
rest of the objects all casted into the basic type "Annuity"
e.g. we have following code:

EntityManager em = null;
try{
em = factory.createEntityManager();
Query query = em.createNamedQuery("GetHolderAnnuities");
query.setParameter("holderId", holder.getId());
return (List<IAnnuity>) query.getResultList();
}

FixedAnnuity fixed1 = new FixedAnnuity();
fixed1.setHolder(holder);
EquityAnnuity equity1 = new EquityAnnuity();
equity1.setHolder(holder);
FixedAnnuity fixed1 = new FixedAnnuity();
fixed2.setHolder(holder);
EquityAnnuity equity2 = new EquityAnnuity();
equity2.setHolder(holder);

List<IAnnuity> annuities = getServerAdapter().findHolderAnnuities(holder);

Only annuities.get(0) returns the correct object as FixedAnnuity, the other 3
objects returned all returned as Annuity

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Catalina Wei added a comment - 10/Aug/07 11:34 PM
The attached patch seemed to have fixed the problem.
The testcase of the Annuity has FetchType EAGER set on both side of a OneToMany relation. An Annuity may have many Payouts.
I'd like to get some feedback from commiters before checking in this patch.
TCK verification is in process.

Catalina Wei made changes - 10/Aug/07 11:34 PM
Field Original Value New Value
Attachment jpa1.0.0.patch [ 12363639 ]
Catalina Wei added a comment - 11/Aug/07 02:53 AM
same patch as the last patch, but using the new naming convention as recommended by the community.

Catalina Wei made changes - 11/Aug/07 02:53 AM
Attachment OPENJPA-313.r564688.patch [ 12363646 ]
Kevin Sutter added a comment - 13/Aug/07 04:10 PM
Catalina,
Thanks for the patch. A couple of questions and/or comments though...

It looks like this updated code is only if we're working with an OpenJPAID oid and subs is true. I can understand the oid part, but what exactly is the subs boolean used for? I know this wasn't your original code, but a quick glance at the code shows a need for a javadoc update at least. You must have spent some time figuring out how this parameter is used. It would be helpful to put add to the javadoc for this method to explain what the subs parameter is used for (at least). Thanks.

Also, I really dislike empty catch clauses. I can't tell if this was on purpose or an oversight. It also forces me to think through the logic whether this exception clause was necessary or not. I think the empty clause is okay, but we should at least put a comment in the clause indicating why we can safely ignore this exception.

I also personally don't like the idea of comparing strings for the strategy type, but it looks like we're just following suit from the existing code. We can only change so much at a time, I suppose... :-)

Thanks again,
Kevin

Catalina Wei added a comment - 14/Aug/07 04:27 AM
add block comments to the code.

Catalina Wei made changes - 14/Aug/07 04:27 AM
Attachment OPENJPA-313.r564688.patch [ 12363754 ]
Repository Revision Date User Message
ASF #565845 Tue Aug 14 17:38:00 UTC 2007 wisneskid Help Catalina committing OPENJPA-313.r564688.patch
Files Changed
MODIFY /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java

Repository Revision Date User Message
ASF #565896 Tue Aug 14 20:17:39 UTC 2007 kwsutter OPENJPA-313. Looks like this patch wasn't quite ready for prime time. I attempted to re-build and re-test right after applying this change and I got several testcase errors in openjpa-persistence-jdbc. I revert back ClassMapping.java and the problems go away. Needs some more work...
Files Changed
MODIFY /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java

Catalina Wei added a comment - 15/Aug/07 02:23 AM
attached revised patch.
mvn clean install ran successful.

Catalina Wei made changes - 15/Aug/07 02:23 AM
Attachment OPENJPA-313.2.patch [ 12363817 ]
Repository Revision Date User Message
ASF #566006 Wed Aug 15 02:24:50 UTC 2007 wisneskid Help Catalina committing OPENJPA-313.2.patch
Files Changed
MODIFY /openjpa/trunk/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java
MODIFY /openjpa/trunk/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java

Kevin Sutter added a comment - 16/Aug/07 02:49 PM
Since Catalina doesn't quite have the necessary karma yet, I will resolve this Issue for her... :-) Thanks, Catalina, for the patch!

Kevin Sutter made changes - 16/Aug/07 02:49 PM
Resolution Fixed [ 1 ]
Status Open [ 1 ] Resolved [ 5 ]
Repository Revision Date User Message
ASF #692299 Thu Sep 04 23:12:27 UTC 2008 ssegu OPENJPA-313.2.patch
Files Changed
MODIFY /openjpa/branches/0.9.7-r547073/openjpa-kernel/src/main/java/org/apache/openjpa/util/OpenJPAId.java
MODIFY /openjpa/branches/0.9.7-r547073/openjpa-jdbc/src/main/java/org/apache/openjpa/jdbc/meta/ClassMapping.java