Hi.. Im a new user on this forum. I have a little problem using hibernate and @WhereJoinTable if I try to add more than one restriction at the 'clause'.
Suppose I have a data model like this:
Code:
public class ForeignPerson implements Serializable {
private Long id;
private List<IdentityNumberHistory> identityHistories;
private transient IdentityNumberHistory currentTemporalIdentity;
private transient IdentityNumberHistory currentPermenentIdentity;
// Other property, getter, setter.
@OneToMany(fetch=FetchType.LAZY, mappedBy="foreigner",
cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE})
public List<IdentityNumberHistory> getIdentityHistories() {
return this.identityHistories;
}
@Transient
@OneToOne(fetch=FetchType.LAZY, mappedBy="foreigner")
@WhereJoinTable(clause="CurrentIdentityNumber=true and IdentityNumberType='TEMPORAL'")
public IdentityNumberHistory getCurrentTemporalIdentity() {
this. currentTemporalIdentity = this.identityHistories.size() != 0 ?
this.identityHistories.get(0) : new IdentityNumberCreationHistory();
return this. currentTemporalIdentity;
}
@Transient
@OneToOne(fetch=FetchType.LAZY, mappedBy="foreigner")
@WhereJoinTable(clause="CurrentIdentityNumber=true and IdentityNumberType='PERMANENT'")
public IdentityNumberHistory getCurrentPemanentIdentity() {
this.currentPermenentIdentity = this.identityHistories.size() != 0 ?
this.identityHistories.get(0) : new IdentityNumberCreationHistory();
return this. currentPermenentIdentity;
}
}
public class IdentityNumberHistory implements Serializable {
private Long id;
private ForeignPerson foreigner;
// Other property, getter, setter.
}
When I try the code, the generated SQL is look like this:
Code:
select <blablabla> from identity_number_creation_history identitynu0_ where identitynu0_.IdentityNumberType=? and identitynu0_.ForeignPersonID=?
Where <blablabla> is selected fields in the query. As you may see, the where clause only ask for IdentityNumberType and ForeignPersonId, no criteria/where clause for CurrentIdentityNumber. When I remove one of criteria in @WhereJoinTable, it is works.
So, I suspect that the 'clause' in the @WhereJoinTable is in problem. Or, of course may be this is my fool and I hope one of you can help me out of this problem. Any suggestion will be so helpful.
The hibernate version is:
Specification-Title: Hibernate Core
Specification-Version: 3.3.1.GA
Specification-Vendor: Hibernate.org
Implementation-Title: Hibernate Core
Implementation-Version: 3.3.1.GA
Where it is a default hibernate version which bring by seam framework 2.2.0 GA.
Thanks.