-->
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.  [ 10 posts ] 
Author Message
 Post subject: Using the "implements" meta tag with composite-id
PostPosted: Fri Nov 07, 2003 8:21 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
I have a class which has both an "implements" meta tag and a composite-id tag. When I use the hbm2java tool to generate java code, the generated composite-id class ends up implementing the interface, as well as the class. Unfortunately, the composite-id class will not compile unless I add the properties defined in the interface, which I can't do.

Mapping file:
Code:
<?xml version="1.0"?>

<!DOCTYPE hibernate-mapping PUBLIC
        "-//Hibernate/Hibernate Mapping DTD//EN"
        "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">

<hibernate-mapping default-cascade="save-update">
     
    <class name="com.foo.bar.data.base.DataObject" table="data_objects">

    <meta attribute="implements">com.foo.bar.data.util.Auditable</meta>
         
    <composite-id name="id" class="com.foo.bar.data.CompositeID" unsaved-value="any">
        <key-property name="foo" type="long" column="foo"/>
        <key-property name="bar" type="long" column="bar"/>
    </composite-id>

    <property name="created" type="timestamp" not-null="true" unique="false"/>
    <property name="modified" type="timestamp" not-null="true" unique="false"/>

    </class>

</hibernate-mapping>


Generates a CompositeID class like this:
Code:
package com.foo.bar.data;

import java.io.Serializable;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;

/** @author Hibernate CodeGenerator */
public class CompositeID implements com.foo.bar.data.util.Auditable,Serializable {

    /** identifier field */
    private long foo;

    /** identifier field */
    private long bar;

    ....
}


Is this intended behavior or a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 07, 2003 9:24 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Submit this to JIRA please.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 08, 2003 5:57 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it ain't a bug ;)

- search for the same question in the forum
- look in the docs for meta tag inheritance
- use inherit="false" on stuff you won't like to be "inherited"

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 1:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I was aware of inhertence features but did not think it applied here. I will have to deal with this with what the Middlegen plugin creates aswell.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Nov 09, 2003 3:14 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
It's like gravity - it applies everywhere ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 12:27 am 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
david, do you still want me to submit it to JIRA?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 5:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
it ain't a hbm2java bug - it's a feature ;)

but I think you could submit it as a "bug" in middlegen which should set inherit="false" if a class or subclass has composite ids.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 2:39 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 1:24 pm
Posts: 213
Location: Richardson, TX
Well, I'm not a middlegen user, so I wouldn't want to throw together a code example. It may be easy to learn, but I don't have the time at the moment.

Turning off meta tag inheritance worked, but it still seems a bit odd that this particular meta tag would ever need to be inherited. The only entities you would want to inherit this meta tag (subclasses or joined subclasses) already do so through java inheritance. I can't think of a situation outside of that where, for the "implements" tag, meta tag inheritance would be desirable, and there's at least one case where it's detrimental. Maybe I lack imagination, though. :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
meta attributes that makes sense to inherit is:

All "scope-*" stuff.
"extends"
"bound", "constrained"

well - that's abot all attribtes ;)

I actually set it in the config.xml to apply it to all hbm.xml files - yes inheritance works at that level too.

I added inheritance to <meta> to avoid typing this stuff in each hbm.xml file/class - but I can see that implements/extends is "weird" with composite-id's but currently I would rather keep the ineritance stuff simple (read: inheritance is semantically the same for all attributes) instead of making special rules....

One could argue that one could allow the user to set the default value for the inherit attribute - then you could switch to an "inherit only explict marked stuff"...?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 11, 2003 5:39 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Don't worry about submitting to JIRA. As far as Middlegen goes I have it under control. Thanks.

Max, Yes the composite key inheritence (as illustrated) is odd which is why I did not think that it applied. In anycase, keep the code simple so don't worry about changing it.


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