-->
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: Middlegen: Inheritance Question
PostPosted: Sun Jun 06, 2004 6:45 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 9:36 am
Posts: 28
Is there any way to tell middlegen you want to treat a one-to-one relationship between two tables as a hibernate inheritance setup (joined subclasses)? I've search the forum and google but haven't found anything useful. As of right now I'm manually editing the hbm.xml files to generate the joined subclass elements, being able to automate this would greatly improve my build process/times.

Cheers,
Tyler


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 06, 2004 9:50 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I could add this - sounds good. Help me by providing an example, eg, ddl, hbm(s) to illustrate how you would like it to look. I assume you want it on a per table setting rather than only global.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 4:02 pm 
Beginner
Beginner

Joined: Thu Apr 29, 2004 9:36 am
Posts: 28
David,

Syntax wise I think something similar to:

Code:
    <table name="users" extends="employees"/>



would work nicely.

As for sample hbms the only changes I make between the standard hbm.xml generated by the Middlegen plugin and my inhertance classes are:

1) rename <class></class> to <joined-subclass></joined-subclass>
2) replace the <id></id> element with a <key></key> element
3) remove the one-to-one association links between both the parent and children classes

Samples:

Code:

Employee.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<class
    name="com.warfrog.hibernate.Employee"
    table="employees"
>
    <id
        name="employeeId"
        type="java.lang.Integer"
        column="employee_id"
    >
        <generator class="native" />
    </id>

    <property
        name="active"
        type="java.lang.Boolean"
        column="active"
        not-null="true"
        length="1"
    >
    <!-- Associations --> 
    <!-- bi-directional one-to-one association to User -->
    <one-to-one
        name="user"
        class="com.warfrog.sterling.brokeronline.hibernate.User"
        outer-join="auto"
   cascade="delete"
    />

...other associations and properties removed...

</class>
</hibernate-mapping>

User.hbm.xml

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<class
    name="com.warfrog.hibernate.User"
    table="users"
>
    <id
        name="userId"
        type="java.lang.Integer"
        column="user_id"
    >
        <generator class="assigned" />
    </id>

    <property
        name="username"
        type="java.lang.String"
        column="username"
        not-null="true"
        length="255"
    />
    <property
        name="password"
        type="java.lang.String"
        column="password"
        not-null="true"
        length="50"
    />
   
    <!-- Associations --> 
    <!-- bi-directional one-to-one association to Employee -->
    <one-to-one
        name="employee"
        class="com.warfrog.sterling.brokeronline.hibernate.Employee"
        outer-join="auto"
        constrained="true"
    />   

...other associations and properties removed...

</class>
</hibernate-mapping>



Becomes

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<class
    name="com.warfrog.hibernate.Employee"
    table="employees"
>
    <id
        name="employeeId"
        type="java.lang.Integer"
        column="employee_id"
    >
        <generator class="native" />
    </id>

    <property
        name="active"
        type="java.lang.Boolean"
        column="active"
        not-null="true"
        length="1"
    >
    <!-- Associations --> 
    <!-- association to User removed -->

<joined-subclass
    name="com.warfrog.hibernate.User"
    table="users"
>
    <key column="user_id"/>

    <property
        name="username"
        type="java.lang.String"
        column="username"
        not-null="true"
        length="255"
    />
    <property
        name="password"
        type="java.lang.String"
        column="password"
        not-null="true"
        length="50"
    />

    <!-- Associations --> 
    <!-- association to Emploee removed -->

...other associations and properties removed...

</joined-subclass>

</class>
</hibernate-mapping>



The only other thing I can think of is making sure that multiple tables can inherit from a single parent (ex: User extends Employee, Manager extends Employee). Let me know if there's anything else I can do to help out.

Thanks again,
Tyler


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 07, 2004 6:59 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Thanks for the information.

Theres a bit of work there, I will have a quick estimate of the effort, I want to release R5 soon. I have been stablising the code so I will most likely wait until I have released R5 before fully commiting to it. It would be nice to include it though - see what happens.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 08, 2004 10:25 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 9:36 am
Posts: 28
David,

Sounds great. Like I said, if there's anything else I can do to help, don't hesitate to let me know.

Cheers,
Tyler


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.