Hi,
Iam using Hibernate 3.0.5 and JDk 1.4. What iam tryin gto achieve is to create an alias for unidirectional Many-to-one association. I want it to perform an outer join which it does as long as i dont use createAlias in my Criteria query. Can you please help me out with this.
My Mapping:-
Code:
<class name="com.domain.businessobjects.RecentSlotTransaction"
table="SLOTTRANSACTIONS" lazy="false" optimistic-lock="none">
<id name="transactionKey" column="TRANSACTIONKEY" type="big_decimal">
<generator class="assigned" />
</id>
<many-to-one name="attendant"
class="com.domain.businessobjects.Attendant" lazy="false"
outer-join="true" update="false" cascade="none" not-null="false"
insert="false" not-found="ignore" fetch="join" optimistic-lock="false">
<column name="CARDNO" />
</many-to-one>
</class>
<class name="com.domain.businessobjects.Attendant"
table="SLOT_ATTENDANTS" lazy="false" where=" TIMEIN !=0 and DATEIN !=0 "
optimistic-lock="none">
<id name="cardNo" column="CARDNO"
type="com.domain.persistence.types.StringAsFixedCharType">
<generator class="assigned" />
</id>
<property name="attendantName" column="ATTENDANTNAME"
not-null="true"
type="com.domain.persistence.types.StringAsFixedCharType" />
</class>
My Business objects:-
Code:
public class RecentTransaction extends MutableBusinessObject implements
Serializable {
private Attendant attendant;
public SlotAttendant getAttendant() {
return attendant;
}
public void setAttendant(SlotAttendant attendant) {
this.attendant = attendant;
}
public class Attendant implements ImmutableBusinessObject{
/* (non-Javadoc)
* @see java.lang.Object#hashCode()
*/
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((attendantName == null) ? 0 : attendantName.hashCode());
result = prime * result + ((cardNo == null) ? 0 : cardNo.hashCode());
return result;
}
/* (non-Javadoc)
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (!(obj instanceof Attendant))
return false;
Attendant other = (Attendant) obj;
if (attendantName == null) {
if (other.attendantName != null)
return false;
} else if (!attendantName.equals(other.attendantName))
return false;
if (cardNo == null) {
if (other.cardNo != null)
return false;
} else if (!cardNo.equals(other.cardNo))
return false;
return true;
}
/**
*
*/
private static final long serialVersionUID = -38107996517669240L;
private String cardNo;
private String attendantName;
public void setCardNo(String cardNo) {
this.cardNo = cardNo;
}
public String getCardNo() {
return cardNo;
}
public void setAttendantName(String attendantName) {
this.attendantName = attendantName;
}
public String getAttendantName() {
return attendantName;
}
}
My DAO code :-
Code:
Criteria aCriteria = getHibernateDAO().getSession().createCriteria(
RecentTransaction.class);
transactions = getHibernateDAO().executeCriteriaSearch(aCriteria);
The above when executed generates a SQl query as follows
Select * from Transactions A left outer join Attendants B ........
But i want to create a alias as follows
Code:
Criteria aCriteria = getHibernateDAO().getSession().createCriteria(
RecentTransaction.class);
aCriteria.createAlias("attendant", "tr").setFetchMode("attendant", FetchMode.JOIN);
transactions = getHibernateDAO().executeCriteriaSearch(aCriteria);
It generates an sql query with inner join. which roughly looks like the below.
Select * from Transactions A inner join Attendants B ........
The question is how do i still get the outer join to be performed even after creating an alias. I also tried to set FetchMode to EAGER and DEFAULT. there is no difference it still generates an inner join. Any help will be appreciated.
Thank you