-->
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: Mapping Question about Base Class Inheritance
PostPosted: Mon Aug 02, 2004 3:10 pm 
Newbie

Joined: Mon Aug 02, 2004 3:02 pm
Posts: 15
I want to use a base class for all of my value objects like:

public class Base {
private Long id;
private String createdBy;
private String createdOn;
private String createdIPAddress;
private String modifiedBy;
private String modifiedOn;
private String modifiedIPAddress;

....getters and setters here.....
}

And now I want all of my other value objects to extend the Base class like:

public class User extends Base {
private String loginName;
private String password;
private Contact contact;
private List roles;

/**
* @return Returns the contact.
*/
public Contact getContact() {
return this.contact;
}
/**
* @param contact The contact to set.
*/
public void setContact(Contact contact) {
this.contact = contact;
}
/**
* @return Returns the loginName.
*/
public String getLoginName() {
return this.loginName;
}
/**
* @param loginName The loginName to set.
*/
public void setLoginName(String loginName) {
this.loginName = loginName;
}
/**
* @return Returns the password.
*/
public String getPassword() {
return this.password;
}
/**
* @param password The password to set.
*/
public void setPassword(String password) {
this.password = password;
}
/**
* @return Returns the roles.
*/
public List getRoles() {
return this.roles;
}
/**
* @param roles The roles to set.
*/
public void setRoles(List roles) {
this.roles = roles;
}
}

Since every table in the database is going to have the fields included in the Base object, the Base object merely represents a common class and not any kind of table, but rather fields on all of the subclass tables. Is there a way to map this in Hibernate or will I need to get rid of the Base class and include all of its fields on all of the subclasses?

Thanks for any help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 3:48 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Quote:
Is there a way to map this in Hibernate or will I need to get rid of the Base class and include all of its fields on all of the subclasses?


This can be implemented easily with XDoclet. You need to define XDoclet tags for the attributes in the superclass, and for the class and attributes in the subclass. The generated mappings (for subclasses) will include the fields from the superclass.

mota


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 4:01 pm 
Newbie

Joined: Mon Aug 02, 2004 3:02 pm
Posts: 15
So for the User object, would I just add the following XDoclet tags:

@hibernate.id name="id" column="USER_ID" type="long" generator-class="native"

So, the name would be the name of the field in the superclass. Is this correct?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 02, 2004 4:03 pm 
Regular
Regular

Joined: Wed Nov 05, 2003 10:57 pm
Posts: 96
Yes


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.