File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hi everyone this is my very first post so please ignore any mistakes and let me know if any Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hi everyone this is my very first post so please ignore any mistakes and let me know if any" Watch "Hi everyone this is my very first post so please ignore any mistakes and let me know if any" New topic
Author

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

mahesh shastri
Greenhorn

Joined: Sep 04, 2010
Posts: 11

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

Joined: Oct 26, 2010
Posts: 198

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();
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hi everyone this is my very first post so please ignore any mistakes and let me know if any
 
Similar Threads
Can a CMR field be part of a compound primary key
export EJB 1.1 - Physical Table Name different from Logical
Jboss does not accept "table-name"...why?
mapping for duplicate rows
problem with the insertion of a text field