I have the following mapping objects:
@Entity(name = "Dialable")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(
name = "DialableType",
discriminatorType = DiscriminatorType.STRING
)
@DiscriminatorValue("Dialable")
@Table(name = "cmn_dialable",
uniqueConstraints = {@UniqueConstraint(columnNames = {"dialableString", "domain_id"})})
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public abstract class Dialable {
...}
@Entity(name = "PhoneNumber")
@DiscriminatorValue("PhoneNumber")
@AttributeOverride(name="name", column = @Column(unique = true))
public class PhoneNumber extends Dialable {
protected Domain domain;
@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "optionalDomainId", nullable = true)
public Domain getDomain() {
return domain;
}
public void setDomain(Domain domain) {
this.domain = domain;
}
...}
@Entity(name = "DomainDialable")
@DiscriminatorValue("DomainDialable")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public abstract class DomainDialable extends Dialable {
protected Domain domain;
@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
public Domain getDomain() {
return domain;
}
public void setDomain(Domain domain) {
this.domain = domain;
}
...}
The table that hold all the objects has reference to Domain table twice. First column is called domain_id and second is optionalDomain_id.
I am using CriteriaAPI to query data from the table above. For this I am adding an Alias in the following way:
session.createCriteria(Dialable.class)
.createAlias("domain","dialableDomain")
.add(Expression.eq("assigned", Boolean.valueOf(true)))
.add(Expression.eq("dialableString", callee))
.add(Expression.disjunction().add(Expression.eq("dialableDomain.id", Long.valueOf(domainId)))
.add(Expression.isNull("domain")))
.uniqueResult();
Please note that I adding only one alias for member "domain".
Resulting SQL is the following:
select this_.id as id21_2_, this_.creationDate as creation3_21_2_, this_.description as descript4_21_2_, this_.lastModificationDate as lastModi5_21_2_, this_.name as name21_2_, this_.status as status21_2_, this_.assigned as assigned21_2_, this_.dialableString as dialable9_21_2_, this_.reachable_id as reachable10_21_2_, this_.domain_id as domain11_21_2_, this_.optionalDomainId as optiona12_21_2_, this_.DialableType as Dialable1_21_2_, dialabledo1_.id as id12_0_, dialabledo1_.creationDate as creation2_12_0_, dialabledo1_.description as descript3_12_0_, dialabledo1_.lastModificationDate as lastModi4_12_0_, dialabledo1_.name as name12_0_, dialabledo1_.status as status12_0_, dialabledo1_.confirmation as confirma7_12_0_, dialabledo1_.domainAdministrator_id as domainAd9_12_0_, dialabledo1_.domainPackage_id as domainPa8_12_0_, dialabledo1_.id as id12_1_, dialabledo1_.creationDate as creation2_12_1_, dialabledo1_.description as descript3_12_1_, dialabledo1_.lastModificationDate as lastModi4_12_1_, dialabledo1_.name as name12_1_, dialabledo1_.status as status12_1_, dialabledo1_.confirmation as confirma7_12_1_, dialabledo1_.domainAdministrator_id as domainAd9_12_1_, dialabledo1_.domainPackage_id as domainPa8_12_1_ from cmn_dialable this_
inner join cmn_domain dialabledo1_ on this_.domain_id=dialabledo1_.id inner join cmn_domain dialabledo1_ on this_.optionalDomainId=dialabledo1_.id
where this_.assigned=? and this_.dialableString=? and (dialabledo1_.id=? or this_.optionalDomainId is null)
What hibernate does it creating the alias twice with the same "alias" while I asked only once. Ofcourse the syntax is incorrect and the query fails since the name is not unique. Moreover the last condition refers not to the relation I requested with an alias.
Can someone help ? Is it a big in Hibernate ?
Hibernate version:3.2.3ga
|