-->
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.  [ 2 posts ] 
Author Message
 Post subject: createAlias() causes two joins with same table name
PostPosted: Sun Apr 22, 2007 10:51 am 
Newbie

Joined: Mon Aug 28, 2006 12:01 pm
Posts: 11
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


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 22, 2007 11:19 am 
Newbie

Joined: Mon Aug 28, 2006 12:01 pm
Posts: 11
I see the problem now, I have two getters with the name of getDomain(). The JoinColumn annotations is good enough for the mapping but the createAlias of CriteriaAPI gets confused.

Shouldn't it be somehow protected or dealtWith ? For example using only one alias ? Or taking specifing the column name for the alias creation ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

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.