File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Criteria and joins" Watch "Criteria and joins" New topic

Criteria and joins

Alex Armenteros
Ranch Hand

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


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


The console output shows 2 instead of 1.

Alex Armenteros
Ranch Hand

Joined: May 05, 2010
Posts: 75
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:
subject: Criteria and joins
It's not a secret anymore!