-->
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: Column mapped both with @Id and @OneToOne
PostPosted: Wed Mar 30, 2011 6:34 am 
Newbie

Joined: Wed Jan 06, 2010 6:34 am
Posts: 8
Location: Amsterdam (NL)
Hi all

I have an entity as below

Code:
@Entity
@Table
public class UserFolder {
    @Id
    @OneToOne(optional = false)
    @JoinColumn(name = "USER_ID")
    private User user;

    @Id
    @OneToOne(optional = false)
    @JoinColumn(name = "FOLDER_ID")
    private FolderTreeItem folderTreeItem;

}


If load/findAll I can navigate the full object graph (userFolder.folderTreeItem.project.id)
but if I want to perform a query using the Criteria approach I am not able

Code:
criteria.add(Restrictions.eq("folderTreeItem.project", mySearchCriteria.getProject()));


The code above doesnt work, looking at the generated sql I can see what happens:
- there is no join between USERFOLDER table and the FolderTreeItem table
- if I remove the @Id from folderTreeItem then the join takes place and I can query

I have solved the problem mapping the field twice, not sure if it is supposed to be like that... anyway I dont undertand why making the column part of the identifier would prevent the table join. Any idea?

Tnx in advance

Beppe


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.