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