-->
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.  [ 14 posts ] 
Author Message
 Post subject: XDoclet not generating sub-class element in base mapping
PostPosted: Fri Dec 10, 2004 7:07 pm 
Newbie

Joined: Fri Dec 10, 2004 6:58 pm
Posts: 4
Hibernate version:
2.1.6

XDoclet version:
1.2.2

I have the following heirachy:


Quote:
User (Interface)
/ \
RegisteredUser PseudoUser



User is mapped via hibernate.class, and I am trying to map the implementors (RegisteredUser and PseudoUser) as subclasses (have tried join-subclass too).

For some reason, XDoclet doesn't seem to notice that these classes implement the User interface, and nothing is put in the User.hbm.xml.

Here is the User interface:

Code:
/**
* @hibernate.class table="user"
*
* @hibernate.discriminator column="type"
*/

public interface User {

    /**
     * @hibernate.id generator-class="native"
     */
    public Long getId();

    public void setId(Long id);

}


Here are the implementors:

Code:
/**
* @hibernate.subclass table="user" discriminator-value="PSEUDO"
*/
public class PseudoUser implements User {


/**
* @hibernate.subclass table="user" discriminator-value="REGISTERED"
*/
public class RegisteredUser implements User {


All that gets generated is:

Code:
   <class
        name="homeabroad.model.User"
        table="user"
        dynamic-update="false"
        dynamic-insert="false"
        select-before-update="false"
        optimistic-lock="version"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Long"
        >
            <generator class="native">
              <!-- 
                  To add non XDoclet generator parameters, create a file named
                  hibernate-generator-params-User.xml
                  containing the additional parameters and place it in your merge dir.
              -->
            </generator>
        </id>

        <discriminator
            column="type"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-User.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>


Any thoughts?

Cheers!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 7:40 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
Have you considered making User an abstract class, rather than an interface alone?

Or create an abstract UserImpl implements User, place the @hibernate.class tags in the UserImpl - have your other children extend UserImpl and implement User


Top
 Profile  
 
 Post subject: User is an interface as RegisteredUser extends something els
PostPosted: Fri Dec 10, 2004 7:48 pm 
Newbie

Joined: Fri Dec 10, 2004 6:58 pm
Posts: 4
Hi,

One reason that User is an interface is that some of the elements that implement User extend other things :/

Is there a reason why having a User interface wouldn't work with hibernate/xdoclet generating it?

If so, then I can try to rework things.....

Cheers,

Dion


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 10, 2004 11:14 pm 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
I think of it this way: your classes can implement any number of interfaces ... how is hibernatedoclet to know which one is the "class" for the hbm.xml file? hibernatedoclet would have to parse through all of the implemented interfaces and take a best guess as to which one it is ... what if more than one declares itself as a @hibernate.class ?
Your domain objects should implement java.io.Serializable as well

I took the hibernate advice and declared a Persitent ancestor for all my domain objects, but I did not declare it a @hibernate.class
Code:
package com.domain;
public class Persistent implements java.io.Serializable {
    protected Long id;
    /**
     * @hibernate.id
    */
    public void setId(Long id) {
        this.id = id;
    }

    public Long getId() {
        return this.id;
    }


This allows me to control the kinds of Ids (Long, UUID, whatever) in one class. Notice the missing @hibernate.class!

For example's sake, a Person, who has a User and Employee child.
There is no actual Person, it's an abstract Ancestor. I could make it PersonImpl implements Person.
Code:
package com.domain;
/**
* @hibernate.class table="Person"
* @hibernate.discriminator
*      column="type"
*      type="string"
*/
public abstract class PersonImpl extends Persistent implements Person {
...
}

-----
/**
* @hibernate.subclass
*/
public class UserImpl extends PersonImpl implements Person, User {
...
}
-------
/**
* @hibernate.subclass
*/
public class EmployeeImpl extends PersonImpl implements Person, Employee {
...
}



It's sort of gross because it's an example. You can have interface Person, you can
Code:
package com.domain;
public interface Person {
  getFirstName(); .... getEyeColor(); ... etc
...
}
----
package com.domain;
public interface User extends Person {
  getLoginId(); ... getPassword(); ... etc.
}
----
package com.domain;
public interface Employee extends Person {
  getEmployeeCode(); .... getJerkBossName(); .... etc
}



etc. Hibernatedoclet can deal with all of that.
I typed a lot of stuff here, hopefully nothing wrong. Debugging code is a lot easier than debugging text ;-)


Top
 Profile  
 
 Post subject: Similar
PostPosted: Sat Dec 11, 2004 12:59 am 
Newbie

Joined: Fri Dec 10, 2004 6:58 pm
Posts: 4
I have a similar situation.

I have an Entity class which has the ID stuff that you mention and also doesn't have a hibernate.class.

If I look at the simplest part of the heirachy I still have:

User interface (which has hibernate.class defined)

PseudoUser class (which implements User interface, and extends Entity, and defines hibernate.subclass)

Why wouldn't hibernatedoclet be able to work out that the only path to a hibernate.class is through the User interface?

Or why not allow: @hibernate.subclass superclass="User" if it needed something more specific?

Cheers,

Dion


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 11, 2004 1:48 am 
Beginner
Beginner

Joined: Wed Oct 01, 2003 3:57 am
Posts: 33
Location: Alpharetta, Georgia
I think that's the point: an interface isn't a class. I've seen references in the docs about using an interface as a proxy, but I haven't done that myself so I'm not sure how it might be done.

I see in the docs Chapter 5: Basic O/R Mapping that
Quote:
It is perfectly acceptable for the named persistent class to be an interface. You would then declare implementing classes of that interface using the <subclass> element. You may persist any static inner class. You should specify the class name using the standard form ie. eg.Foo$Bar.


But I'm not sure if XDoclet knows that. There are certain things that Hibernate says you can do that hibernatedoclet doesn't yet know how to do. It appears that the XDoclet guys aren't working on 1.2x anymore, are concentrating their efforts on 2.x


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 7:42 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
khote wrote:
But I'm not sure if XDoclet knows that. There are certain things that Hibernate says you can do that hibernatedoclet doesn't yet know how to do. It appears that the XDoclet guys aren't working on 1.2x anymore, are concentrating their efforts on 2.x


You quite right. But it's not "guys" - it's only me at the moment.

Thuogh plugion for XD2 is already usable and is in better shape than 1.2 ( and it got new feqatures, like automatic tag validation )

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 12:34 pm 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
As for interfaces as root of class hierarchy - current CVS version of xdoclet-plugin for XD2
supports this.

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 13, 2004 4:00 pm 
Newbie

Joined: Mon Dec 13, 2004 3:47 pm
Posts: 3
Location: London
I filed a bug + patch on this one year ago (http://opensource.atlassian.com/project ... se/XDT-697) but the patch still hasn't been applied.

In the meantime I've improved the patch, it deals correctly with interface subclassing and is used "in production", as our project relies heavily on persistent interfaces.

it's against xdoclet 1.2.2, the url is http://www.trampolinesystems.com/~jan/x ... face.patch


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 7:51 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
jberkel wrote:
I filed a bug + patch on this one year ago (http://opensource.atlassian.com/project ... se/XDT-697) but the patch still hasn't been applied....


hibernate support in 12 seems to be orphaned. I used to do this, but meanwhile I moved to xdoclet 2.0 , so all my work is put there...
( you are welcome to try it out )

2.0 uses jelly templates which are better structured / readable / easier to develop.

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 10:50 am 
Newbie

Joined: Mon Dec 13, 2004 3:47 pm
Posts: 3
Location: London
ko5tik wrote:
jberkel wrote:
I filed a bug + patch on this one year ago (http://opensource.atlassian.com/project ... se/XDT-697) but the patch still hasn't been applied....


hibernate support in 12 seems to be orphaned. I used to do this, but meanwhile I moved to xdoclet 2.0 , so all my work is put there...
( you are welcome to try it out )

2.0 uses jelly templates which are better structured / readable / easier to develop.


how difficult is it to migrate from 1.2 to 2.0 ?
one particular feature we need is to have an interface as root persistent class, and then have implementing subclasses in the same hierarchy, sometimes with 'gaps' (e.g. non hibernated classes) in between
like

Interface (persistent) --> Extending Interface (persistent) --> implementing class --> subclass (persistent)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 15, 2004 10:56 am 
Senior
Senior

Joined: Wed Aug 27, 2003 4:08 am
Posts: 178
Location: Wiesbaden, Germany
jberkel wrote:
how difficult is it to migrate from 1.2 to 2.0 ?
one particular feature we need is to have an interface as root persistent class, and then have implementing subclasses in the same hierarchy, sometimes with 'gaps' (e.g. non hibernated classes) in between
like

Interface (persistent) --> Extending Interface (persistent) --> implementing class --> subclass (persistent)


Not so difficult. Collection tags have changed slightly ( collection- part was dropped ) , base interface is supported in curent cvs version ( did not had a chance yet to deploy fresh snapshots on codehaus ) - you can rebuild it easily from sources

This also would serve as example how xdoclet-2 is started.

_________________
Got new hibernate xdoclet plugin? http://www.sourceforge.net/projects/xdoclet-plugins/
... Momentan auf der Suche nach neuen Projekt ode Festanstellung....


Top
 Profile  
 
 Post subject: Xdoclet 1.2.2 support is still there.
PostPosted: Mon Jan 17, 2005 9:10 am 
Newbie

Joined: Mon Apr 26, 2004 12:51 pm
Posts: 3
Location: Stuttgart, Germany
Konstantin is of course supporting his Xdoclet 2 work.
But nevertheless, Xdoclet 1.* is not orphanded.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 17, 2005 7:26 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
For various reasons I need to keep using 1.2.x (one is lack of plugins for the 2.0 branch). I would like to see someone take on 1.2.x and apply (after checking) these patches and (my requirements) implement basic support for hibernate 3.0 . As much as I would like someone else to do it - if I can get commit access I will start the process. I see this as necessary as general application of Java 5.0 will take some time (as it has for other JDKs).

So Konstantin is it possible you giving me commit access to the 1.2.x branch? please.


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