Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Criteria and joins

 
Alex Armenteros
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic