-->
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.  [ 3 posts ] 
Author Message
 Post subject: xdoclet for java2dbm
PostPosted: Fri Jan 30, 2004 5:26 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
I want to use the 'Persistent' base class model as discussed in the documentation.

I am doing TOP DOWN... so xsd --> java --> hbm --> ddl.

I am trying to run the xdoclet to hbm process, but I get an error stating that my class has no ID attribute.

I am basically trying this:

/**
* @hibnernate.class
* table="Widget"
*/
public class Foo extends Persistent{

public String val = null;

/** @hibernate.property */
public String getVal(){
return val;
}

public void setVal(String val){
this.val = val;
}

}

AND

/**
* @hibnernate.class
* table="Hoser"
*/
public class Bar extends Persistent{

public String vallll = null;

/** @hibernate.property */
public String getVallll(){
return val;
}

public void setVal(String vallll){
this.vallll = vallll;
}

}

AND

/**
* @hibnernate.class
*/
public class Persistent implements .... {

public Serializable identity = null;

/** @hibernate.id*/
public Serializable getIdentity(){
return identity;
}

public void setIdentity(Serializable id){
this.identity= id;
}

}


-------

The idea hear is that I use xdoclet to define what table the Foo class should map to. But I am unsure how map the id to the key for Foo's table Widget. Say: widgetId for example but for Bar's table the ID would map to HoserId.

How would I acheive this in xdoclet....

I want to do this so I don't have to stick id attributes in all my pojo's which are tightly bound to my XSD's.


?? I thought it would be simple.. but I am just not having any luck.

Any feedback would be greatly appreciated.


Top
 Profile  
 
 Post subject: one solution
PostPosted: Fri Jan 30, 2004 5:47 pm 
Regular
Regular

Joined: Mon Nov 03, 2003 6:10 am
Posts: 75
One solution I have found is to add the following to each child class:

For Foo in example above for instance:

/**
* @hibernate.id
* column="fooId"
* generator-class="hilo"
*/
public Long getIdentity(){
return this._id;
}


Is it necessary to do the setter? Is there anything I am missing here.. or is the the correct way to do it?

Would it be more correct to do:

/**
* @hibernate.id
* column="fooId"
* generator-class="hilo"
*/
public Long getIdentity(){
return (Long) super.getIdentity();
}


Or something similar? Since the Persistent Base class is Serializable I don't know how safe it is to cast it this way. I guess if I also put in a setter that took a Long indentity value I would be better off?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 31, 2004 8:02 am 
Beginner
Beginner

Joined: Thu Jan 08, 2004 4:40 am
Posts: 48
Location: Bangkok, Thailand
Hi
We think this can help you, you can just take out @hibernate.class from Persistent class and keep all the rest as it's. This might work because We also implement in this way as well. This is my Class detail.


package com.netplus.workstation.user.hibernate.entity;

import java.io.Serializable;

public abstract class HibernateEntity implements Serializable {

protected Long id;
protected String name;

/**
* @hibernate.id
* generator-class="assigned"
* unsaved-value="null"
* @castor.field
* type = "java.lang.Long"
* @castor.field-xml
* name = "id"
* node = "attribute"
*/
public Long getId() {
return this.id;
}

public void setId(Long id) {
this.id = id;
}

/**
* @hibernate.property
* @castor.field
* type = "java.lang.String"
* @castor.field-xml
* name = "name"
* node = "attribute"
*/
public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}

public int hashCode(){
return this.id.intValue();
}
}

===============================================
package com.netplus.workstation.user.hibernate.entity;

import com.netplus.workstation.user.Group;
import com.netplus.workstation.user.User;
import java.security.Principal;
import java.util.Enumeration;
import java.util.Set;
import java.util.Iterator;
import java.util.HashSet;
import java.util.Vector;

/**
* @hibernate.class table="GROUPS"
*/
public class HibernateGroup extends HibernateEntity implements Group {
private String description;
private Set users;

/**
* @hibernate.property
*/
public String getDescription() {
return this.description;
}

public void setDescription(String description) {
this.description = description;
}

/**
* @hibernate.set name="users" lazy="false" table="GROUPS_USERS"
* @hibernate.collection-key column="groupId"
* @hibernate.collection-many-to-many column="userId"
* class="com.netplus.workstation.user.hibernate.entity.HibernateUser"
*/
public Set getUsers() {
return this.users;
}
......................................

==============================================================

package com.netplus.workstation.user.hibernate.entity;

import com.netplus.workstation.user.Group;
import com.netplus.workstation.user.User;
import java.util.*;

/**
* @hibernate.class table="USERS"
*/
public class HibernateUser extends HibernateEntity implements User {

private String password;
private Set groups;

/**
* @hibernate.property
* @castor.field
* type = "java.lang.String"
*
* @castor.field-xml
* name = "password"
* node = "attribute"
*/
public String getPassword() {
return this.password;
}

public void setPassword(String password) {
this.password = password;
}
/**
* @hibernate.set name="groups" lazy="false" table="GROUPS_USERS"
* @hibernate.collection-key column="userId"
* @hibernate.collection-many-to-many column="groupId"
* class="com.netplus.workstation.user.hibernate.entity.HibernateGroup"
*
* @castor.field
* type = "com.netplus.workstation.user.hibernate.entity.HibernateGroup"
* collection = "set"
*/
public Set getGroups() {
return this.groups;
}

public void setGroups(Set groups) {
this.groups = groups;
}


By the way, we use Xdoclet1.2 with maven..Thanks balloonMan for source code

_________________
<name>arin</name>
<at>netplus software</at>


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