-->
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.  [ 18 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: "extends" meta attribute in Tools 3.1 beta1
PostPosted: Tue Nov 01, 2005 8:14 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Hibernate Tools 3.1 beta1

I know this has been asked before, but I haven't seen a definitive answer.

Why is the "extends" meta attribute allowed for subinterfaces, but ignored for subclasses? Since <class> could potentially be an interface, and its <subclass> tag could be a concrete class, doesn't it seems reasonable to allow "extends" for the <subclass> tag? At worse, its just a compile error if someone misuses it. Seems like a strange restriction to me. For example:

<class name="BaseIF">
<meta attribute="interface" inherit="false">true</meta>

<subclass name="BaseImpl"/>

<subclass name="SubIF">
<meta attribute="interface" inherit="false">true</meta>

<subclass name="SubImpl">
<meta attribute="extends" inherit="false">BaseImpl</meta>
</subclass>

</subclass>

</class>

Could someone on the Tools team respond? I've looked at the source code, and it doesn't seem to be a huge change.

Thanks!


Top
 Profile  
 
 Post subject: Re: "extends" meta attribute in Tools 3.1 beta1
PostPosted: Wed Nov 02, 2005 2:04 am 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
boutwell wrote:
<class> could potentially be an interface, and its <subclass> tag could be a concrete class


why are you doing this? beware of of constant interface antipattern.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 12:21 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Huh? What has the constant interface antipattern got to do with anything?

I have a parallel hierarchy of interfaces to implementations that I'd like to generate through hbm2java.

From the tags above, you can see that a <subclass> tag can represent a concrete class, which implements an interface represented by it's parent <class> tag. hbm2java will generate the appropriate "implements" code for the class->subclass relationship here, but ignores the extends attribute. It seems totally reasonable (IMHO) to allow the extends meta attribute in the case of a parent <class>/<subclass> being an interface.

I actually hacked my own version of hbm2java that does that very thing, however I'm not a big fan of such customization. I'd rather that logic be in the standard distro, if there are no valid objections to it.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 12:44 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
you want

BusinessImpl extends BusinessIntf

rather than

BusinessImpl implements BusinessIntf ??


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 1:25 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Here's the structure I need:
--------------------------------------------------------------------------

public interface BaseIF

public class BaseImpl implements BaseIF

public interface SubIF extends BaseIF

public SubImpl extends BaseImpl implements SubIF

--------------------------------------------------------------------------

hbm2java will generate everything fine from the maps, except that it will not generate the 'extends BaseImpl' on the SubImpl class, even though I have it defined with a meta attribute.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
and what does your mapping actually map ?

The code will only generate ONE of these hierachies at the time, so some black magic is required to do it properly. today we just add extends/implements as pure strings - we do not reflect upon them in any way - thus a subclass logically cannot extends anything else than its superclass...

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 5:31 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Quote:
thus a subclass logically cannot extends anything else than its superclass...


In the context of java code, I agree with you.

But in the context of maps, Hibernate allows for superclasses to be represented as interfaces. In this case (see the initial post for the map example) the subclass is implementing the superclass (the interface), not extending it.

In my specific case, the mapping maps a hierarchy of interfaces, with each interface having a mapped implementation subclass. Each mapped implementation class needs to be able to extend the implementation class of its superinterface. (See my previous posts for the map/code example)

Also, I have the mapped properties/associations defined in the interface mapping, and the getter/setters are generated in the interface. It would seem logical that the getter/setter implementations would be generated in the subclass, but they are not.

I've been using this mapping strategy with success in an application for six months. If you have particular objections to using this mapping strategy, whether theoretical or practical, I'd be glad to hear them, as well as any alternatives.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 5:45 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
i have no idea what you are talking about ;)

which initial post has a map example ?

and interface generation should work - just need to have <meta attribute='interface'>true</meta>.

the big problem with your stuff is that you want the mapping files and exporters to generate two things...you will need to give me a full example of what the mapping look like and what stuff you want generated - otherwise i think i'll just keep misunderstanding you since your strategy looks really overcomplex from my point of view ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:38 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Fair enough.

Here's a map file:

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >

<hibernate-mapping>

    <class name="BaseIF"
        table="BASE" proxy="BaseIF">
        <meta attribute="interface" inherit="false">true</meta>

        <id name="baseId" type="Long" column="BASE_ID">
            <generator class="sequence"><param name="sequence">BASE_SEQ</param></generator>
        </id>

        <discriminator column="BASE_TYPE" type="string" length="30"/>

        <property name="modifyDate" type="timestamp" column="MODIFY_DATE" not-null="true" length="7" />
        <property name="modifyUserId" type="string" column="MODIFY_USER_ID" not-null="true" length="30" />

        <subclass name="BaseImpl" discriminator-value="null" proxy="BaseImpl"/>

        <subclass name="SubIF" extends="BaseIF" discriminator-value="null" proxy="SubIF">
            <meta attribute="interface" inherit="false">true</meta>

            <subclass name="SubImpl" discriminator-value="SUB_1" proxy="SubImpl">
                <meta attribute="extends" inherit="false">BaseImpl</meta>
            </subclass>

            <subclass name="SubSubIF" extends="BaseIF" discriminator-value="null" proxy="SubSubIF">
                <meta attribute="interface" inherit="false">true</meta>

                <property name="subsubProperty" type="int" column="SUB_SUB_PROP" not-null="true"/>

                <subclass name="SubSubImpl" discriminator-value="SUB_1" proxy="SubSubImpl">
                    <meta attribute="extends" inherit="false">SubImpl</meta>
                </subclass>
           
            </subclass>

        </subclass>

    </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:42 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Here's the BaseIF code. This works fine.

Code:
// Generated Nov 2, 2005 11:41:19 AM by Hibernate Tools 3.1.0 beta1

import java.util.Date;

/**
* BaseIF generated by hbm2java
*/

public interface BaseIF  {

   /**
    */
   public Long getBaseId();
   
   public void setBaseId(Long baseId);

   /**
    */
   public Date getModifyDate();
   
   public void setModifyDate(Date modifyDate);
   /**
    */
   public String getModifyUserId();
   
   public void setModifyUserId(String modifyUserId);

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:47 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
Here's what I had generating with my customized alpha5 version of hbm2java (what I need):

Code:
import java.util.*;

/**
$c2j.getJavaDoc($clazz, $render.eval($ctx, "$c2j.getDeclarationName($clazz) generated by hbm2java"),0)
*/
public class BaseImpl  implements BaseIF,java.io.Serializable {

    // Fields   

     private Long baseId;
     private Date modifyDate;
     private String modifyUserId;


    // Constructors

    /** default constructor */
    public BaseImpl() {
    }
   
    // Property accessors

    /**
     *
     */
    public Long getBaseId() {
        return this.baseId;
    }
   
    public void setBaseId(Long baseId) {
        this.baseId = baseId;
    }

    /**
     *
     */
    public Date getModifyDate() {
        return this.modifyDate;
    }
   
    public void setModifyDate(Date modifyDate) {
        this.modifyDate = modifyDate;
    }

    /**
     *
     */
    public String getModifyUserId() {
        return this.modifyUserId;
    }
   
    public void setModifyUserId(String modifyUserId) {
        this.modifyUserId = modifyUserId;
    }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:53 pm 
Expert
Expert

Joined: Mon Jul 04, 2005 5:19 pm
Posts: 720
<class name="BaseImpl" table="base_table" >
<meta attribute="implements">BaseIntf</meta>

<subclass name="ChildImpl" extends="BaseImpl" >
<meta attribute="implements">ChildIntf</meta>

then ... seperate files for interface hierarchy.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:55 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
I skipped down to the SubSubIF/Impl:

Code:
import java.util.*;

/**
$c2j.getJavaDoc($clazz, $render.eval($ctx, "$c2j.getDeclarationName($clazz) generated by hbm2java"),0)
*/
public interface SubSubIF extends SubIF  {

        /**
    */
   public int getSubsubProperty();
   
   public void setSubsubProperty(int subsubProperty);

}

Code:
import java.util.*;

/**
$c2j.getJavaDoc($clazz, $render.eval($ctx, "$c2j.getDeclarationName($clazz) generated by hbm2java"),0)
*/
public class SubSubImpl extends SubImpl implements SubSubIF,java.io.Serializable {

    // Fields   

     private int subsubProperty;


    // Constructors

    /** default constructor */
    public SubSubImpl() {
    }
   
   
   
   

    // Property accessors


    /**
     *
     */
    public int getSubsubProperty() {
        return this.subsubProperty;
    }
   
    public void setSubsubProperty(int subsubProperty) {
        this.subsubProperty = subsubProperty;
    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 3:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
so i still don't get what your problem is ;)

apparently you can adjust the template to generate what you want..

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2005 2:37 pm 
Beginner
Beginner

Joined: Thu Jan 29, 2004 6:51 pm
Posts: 24
Location: Boulder, CO USA
I modified PojoTypeDeclaration.vm to get output the extends meta attribute, but I'm still trying to figure out how to get the properties defined in the interface to show up in the implementation. Something in the getAllPropertiesIterator() method.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 18 posts ]  Go to page 1, 2  Next

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.