I have a 2 classes that share a UUID and are uni-directionally mapped. I use the UUID to group related rows, and this group shares many details (this is just an example):
@Entity @Table
class Something {
@Id @Column("something_id")
private Long id;
private String uuid = UUID.randomUUID().toString();
@OneToMany
@JoinColumn("uuid")
private List<Detail> details = new LinkedList<Detail>();
}
@Entity @Table
class Detail {
@Id @Column("detail_id")
private Long id;
private String value;
private String uuid;
}
I’m attempting to use Criteria:
Criteria c = getSession().createCriteria(Something.class).createAlias("details", "detail").add(Restrictions.eq("detail.value", someValue));
This is all fine and dandy, but I’m not getting results because of the join:
inner join DETAIL d1_ on this_.SOMETHING_ID=d1_.UUID
Is it possible to specify:
inner join DETAIL d1 on this_.UUID=d1.UUID
I would have expected the join to use the @JoinColumn annotaiton to find the column to join on. I see that I can specify a join type, but I don’t see a way to specify the actual column.
The join is using the
JoinColumnannotation since it’s joining ond1_.UUID. However, because you didn’t specify thereferencedColumnNameelement, the foreign key is assumed to refer to the primary key of the referenced table (this_.SOMETHING_ID), hence the obtained result.In other words, try this:
I’m not sure to understand the benefit but let’s say it’s another story.