-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Parent and child relation on same object criteria example
PostPosted: Tue Jan 28, 2014 8:57 am 
Newbie

Joined: Tue Jan 28, 2014 8:23 am
Posts: 1
Hi
I used a criteria to join two tables and the following sql was executed.

select a.id as id, a.details as details, event2_.EVENT_ID as EVENT1, event2_.ASSET as ASSET2_28_0_, event2_.SCORE as SCORE28_0_, event3_.EVENT_ID as EVENT2, riskevent3_.ASSET as ASSET2_28_1_, event3_.SCORE as SCORE28_1_ from ORDERHISTORY a, EVENT event2_, EVENT event3_ where a.EVENT_ID=event2_.EVENT_ID(+) and event2_.PARENT_EVENT_ID=event3_.EVENT_ID(+) and a.ORDER_ID=?

As Iam using Criteria I do not want to include any columns related to event3 and do want to include condition "event2_.PARENT_EVENT_ID=event3_.EVENT_ID(+)".

Here is my Criteria
Criteria criteria = session.createCriteria(OrderHistory.class);

criteria.add(Restrictions.eq("OrderId", "1124"));

criteria.setFetchMode("B", FetchMode.JOIN);


Class History {
@ManyToOne
@JoinColumn(name="EVENT_ID")
private Event event;
.....
other columns
}

Class B {

@ManyToOne
@JoinColumn(name="EVENT_ID")
private Event event;
....
Other columns
}


Class Event {

@ManyToOne
@JoinColumn(name="PARENT_EVENT_ID")
private Event event;

.....
Other columns here...

}


The problem is in Event class i have reference to same Event as parent id.
So my query is by using criteria can we ignore the event3 related conditions and columns.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.