Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hi everyone this is my very first post so please ignore any mistakes and let me know if any

 
mahesh shastri
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am using Hibernate and postgrSQL in my project . I am in a situation where I need to do self-join for a table and I want to use
one- to-many relationship for that. Where my table contains few fields in which one of the field say x field contains the value of
primary key which can be null. Now sometimes I need to fetch records which have identical values in field x.
how do i configure this in hbm.xml ?


Thanks and Regards
 
Sai Hegde
security forum advocate
Ranch Hand
Posts: 212
1
Android Flex Google App Engine
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use DetachedCriteria for the object and set the projection for the join field.

Code Snippet -

DetachedCriteria dc = DetachedCriteria.forClass(Table.class);
dc.add(Restrictions.eq("x", value1);
dc.setProjection(Property.forName("y"));
Criteria c = session.createCriteria(Table.class);

c.add(Property.forName("y").in(dc));
c.list();
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic