The moose likes Object Relational Mapping and the fly likes Criteria and joins Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Criteria and joins" Watch "Criteria and joins" New topic
Author

Criteria and joins

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 46
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: 46
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
 
 
subject: Criteria and joins
 
Threads others viewed
AND/OR
join in 3 tables
OneToOne mapping with 2 composite keys using JPA
inserts into join tables
Criteria Paging is not working
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com