aspose file tools*
The moose likes Object Relational Mapping and the fly likes Criteria and joins Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria and joins" Watch "Criteria and joins" New topic
Author

Criteria and joins

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 67
I have a DB model with 4 tables related and I'm trying this...



Relations

tableA n:1 tableB
tableB 1:n tableC
tableC n:1 tableD


Now I have these registries


A1 ----> B1 ----> C1 ----> D1
----> C2 ----> D2


I want to filter and get only C1 and D1

But when I do

System.out.println(val.tableB.tableC.size());

The console output shows 2 instead of 1.


Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 67
Solved like this.

Change line 3 to:


Criteria cr2 = cr.createCriteria("tableB", CriteriaSpecification.LEFT_JOIN).createCriteria("tableC", CriteriaSpecification.LEFT_JOIN);

and then

D.fieldD to tableD.fieldD

C.fieldC to fieldC
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Criteria and joins
 
Similar Threads
Criteria Paging is not working
inserts into join tables
AND/OR
OneToOne mapping with 2 composite keys using JPA
join in 3 tables