Hi all,
I would like to know how i can map a joined-subclass key using xdoclet, when the key is composite.
For example, i have a class abstractuser, which composite-key is the class AbstractUser.PK, and a subclass Admin. I can map the composite-key of abstractuser, but i cant do the same for admin. The code for the classes is the following:
AbstractUser.java:
/**
* @hibernate.class table="user"
*
*/
public abstract class AbstractUser implements ValueObject {
protected PK primaryKey;
protected String password;
public PrimaryKey getPrimaryKey() {
return getPK();
}
public void setPrimaryKey(PrimaryKey pk) {
this.primaryKey = (PK)pk;
}
public void setPrimaryKey(Serializable pk) {
if (pk instanceof Collection) {
Collection c = (Collection)pk;
Iterator it = c.iterator();
setPrimaryKey(new PK(((Long)it.next()).longValue(), (String)it.next()));
} else {
}
}
/**
* @hibernate.id generator-class="assigned"
*/
private PK getPK(){
return this.primaryKey;
}
/**
* @hibernate.property
*/
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//AbstractUser.PK:
public static class PK implements PrimaryKey {
private long code;
private String partnerCode;
public PK() {
this(-1,null);
}
public PK(long code, String partnerCode) {
this.code = code;
this.partnerCode = partnerCode;
}
/**
* @hibernate.property
*/
public long getCode() {
return this.code;
}
public void setCode(long code){
this.code = code;
}
/**
* @hibernate.property
*/
public String getPartnerCode(){
return this.partnerCode;
}
public void setPartnerCode(String partnerCode){
this.partnerCode = partnerCode;
}
public boolean equals(Object o){
AbstractUser.PK pk = (AbstractUser.PK) o;
if (this.code == pk.getCode() && this.partnerCode.equals(pk.getPartnerCode())){
return true;
}
else{
return false;
}
}
}
}
Admin.java:
/**
* @hibernate.joined-subclass
* @hibernate.joined-subclass-key column="code"
*/
public class Admin extends AbstractUser {
}
I posted before saying that i was having some problems to make schemaexport task find the AbstractUser.PK class. The abstractuser.hbm.xml has the following code:
<hibernate-mapping>
<class
name="com.smartprice.eb.valueobject.AbstractUser"
table="user"
dynamic-update="false"
dynamic-insert="false"
>
<composite-id
name="PK"
class="com.smartprice.eb.valueobject.AbstractUser.PK"
>
<key-property
name="code"
type="long"
column="code"
/>
<key-property
name="partnerCode"
type="java.lang.String"
column="partnerCode"
/>
</composite-id>
...
if i change the line
class="com.smartprice.eb.valueobject.AbstractUser.PK"
to
class="com.smartprice.eb.valueobject.AbstractUser$PK"
it finds the class.
Does anyone know why this is hapenning?
Leonardo
|