-->
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.  [ 5 posts ] 
Author Message
 Post subject: id generation with inheritance and xdoclet
PostPosted: Tue Mar 02, 2004 11:18 am 
Beginner
Beginner

Joined: Mon Dec 08, 2003 12:15 am
Posts: 47
Our application is composed of a super class that all of persistent classes inherit from.

Ex:
public abstract class SuperClass implements Lifecycle {


public long getId() {
return this.id;
}
//...rest of code
}

Ex: Subclass
public class SubClass extends SuperClass{

/**
* @hibernate.property
* column="id"
*/
public long getId() {
return super.getId();
}

//...class definition goes here
}

What we are trying to accomplish is to tag these classes with xdoclet to automate the process of file generation. The challenge that I am running into is that I have to override the method getId in the subclass in order for the id to be generated in the mapping file.

We want to avoid this altogether in the subclass.

Does anyone know of a way to not have to override the method getId in the subclass and at the same time be able to generate the id in the mapping document.

Keep in mind that for all the documents in our application the id generation would look like this:

<id
name="id"
column="id"
type="long"
>
<generator class="native">
</generator>
</id>

This is how it was designed from the ground up so we're stuck with it whether it is architecturally right or wrong.

Any help in this subject would be greatly appreciated since we are under a pretty tight deadline.

Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 02, 2004 6:16 pm 
Regular
Regular

Joined: Fri Jan 16, 2004 4:48 am
Posts: 56
Just move the hibernate.id tags to your abstract class where you define getId and setId. Remove the getId and setId from your child class.

Thanks
Shishir


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 1:47 pm 
Newbie

Joined: Tue Mar 30, 2004 12:49 pm
Posts: 1
Hi,

I have the same problem here where I have a SuperClass A which contains the id property and SubClass B which inherits from A. An example would be:

public class B {
private Long id;

/*
* @hibernate.id generator-class="native" type="long" column="id"
* @return
*/
public Long getId() {
return id;
}

....
....
}

/**
* @hibernate.class
*/
public class A extends B {
....
....
}

If I do this, I get a hibernatedoclet compilation error saying that Class A misses the ID property. Am I doing this correctly? Is there more I have to do in order to get hibernate to parse through the superclass to find the ID field?


Help is much appreciated!

Paul


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 30, 2004 2:52 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
/**
* @hibernate.class
*/



you don't need this for class A


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 12, 2004 4:06 am 
Newbie

Joined: Mon Feb 09, 2004 5:49 am
Posts: 17
were you able to find a solution for this? i too, have a "Persistent.java" class.

I have something such as a User object that extends the Persistent class. User will have its own table with its own ID key in the table called "u_id"


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