-->
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.  [ 4 posts ] 
Author Message
 Post subject: xdoclet, joined-subclass and composite-key
PostPosted: Fri Jun 25, 2004 8:36 pm 
Newbie

Joined: Thu Jun 24, 2004 1:49 pm
Posts: 4
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 1:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Man your PK class is an inner class, the $ is expected

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 1:54 pm 
Newbie

Joined: Thu Jun 24, 2004 1:49 pm
Posts: 4
Yes, I noticed. The point is that xdoclet is generating that maping file. Why isnt it generating the full class name with a '$'?

regards,

Leorazuk


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 28, 2004 3:53 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
This is a bug :-)
Put it in XDoclet JIRA please

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.