[
http://opensource.atlassian.com/projects/hibernate/browse/HBX-793?page=co...
]
Rob Jellinghaus commented on HBX-793:
-------------------------------------
OK, it seems that the behavior of "inherit" changed dramatically between
hibernate2 and hibernate3.
I uploaded an example of the same mapping, with build targets for both the hibernate2 and
hibernate3 versions of hbm2java. The same mapping file works great under hibernate2 but
produces corrupt output (as described above) under hibernate3.
Adding inherit="false" to the parent meta attributes fixes the problems with
Hibernate3, for both generated-class and scope-get/set.
I'm pretty sure that the root problem is that when you redeclare an inherited meta
atttribute in Hibernate2, the redeclaration overrides the parent meta declaration. Which
I would strongly argue is the correct behavior. But in Hibernate3, the redeclared meta
attribute gets *concatenated* to the parent (inherited) attribute. Is there ever any
situation where that is the right behavior??? I can't imagine any right now...?
Also, the current Hibernate3 documentation on meta inheritance --
http://www.hibernate.org/hib_docs/tools/reference/en/html_single/#d0e1630 -- doesn't
describe what the behavior of overriding an inherited meta attribute should be.
If I can make the time, I will dig into the source code of each generator to see exactly
what Hibernate2 did differently, but I've been converting all our production code to
Hibernate3 and have gotten hung up on this for too long already, so I'll have to come
back to it later (I'll have to just fix the mappings for now).
The frustrating part is that there really isn't a specification, and without a clear
spec, bugginess is in the eye of the beholder. If people think that the Hibernate3
behavior is a bug (and I would like to hear a good argument as to why it isn't), then
please vote for this issue.
Inherited meta attributes are totally broken
--------------------------------------------
Key: HBX-793
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-793
Project: Hibernate Tools
Type: Bug
Components: hbm2java
Versions: 3.2beta8
Environment: Hibernate 3.2.0cr8, Hibernate Tools 3.2.0cr8
Reporter: Rob Jellinghaus
Attachments: hbm2java_meta_testcase.zip
Original Estimate: 2 days
Remaining: 2 days
Inherited / overridden meta attributes are totally broken.
By "totally broken" I mean that they are essentially concatenated in the output
template, rather than being overridden properly.
There is already an existing bug
http://opensource.atlassian.com/projects/hibernate/browse/HBX-621 that is one
manifestation of this underlying problem for <meta attribute="scope-get">
and <meta attribute="scope-get">. The exact same bug reappears for
<meta attribute="generated-class">.
Here is an example that shows the bug appearing in both attributes. The following
mapping (simplified):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.nimblefish.core.domain.useraccesscontrol.Permission"
table="permission">
<meta
attribute="generated-class">com.nimblefish.core.domain.generated.PermissionGen</meta>
<id column="id" name="id" type="long"
unsaved-value="null">
<meta attribute="use-in-tostring">true</meta>
<generator class="native"/>
</id>
<!-- other properties deleted -->
<joined-subclass
name="com.nimblefish.core.domain.useraccesscontrol.Role"table="role">
<meta
attribute="generated-class">com.nimblefish.core.domain.generated.RoleGen</meta>
<meta attribute="scope-set">protected</meta>
<key column="id"
foreign-key="fk_role_sub_permission"/>
<set name="grantedPermissions" inverse="true"
table="role_to_granted_permission">
<meta attribute="scope-set">public</meta>
<key column="role_id"
foreign-key="fk_granted_permission_role"/>
<many-to-many
class="com.nimblefish.core.domain.useraccesscontrol.Permission"
column="permission_id" foreign-key="fk_role_granted_permission"/>
</set>
<!-- other properties deleted -->
</joined-subclass>
</class>
</hibernate-mapping>
Produces the following class, in the directory
<out-dir>/PermissionGencom/nimblefish/core/domain/generated/RoleGen.java (that is
NOT a typo):
package
com.nimblefish.core.domain.generated.PermissionGencom.nimblefish.core.domain.generated;
// Generated Oct 27, 2006 9:58:57 PM by Hibernate Tools 3.2.0.beta8
import com.nimblefish.core.domain.useraccesscontrol.TargetObjectContainer;
import java.util.HashSet;
import java.util.Set;
/**
* RoleGen generated by hbm2java
*/
public class RoleGen extends com.nimblefish.core.domain.useraccesscontrol.Permission
implements java.io.Serializable {
// Fields
// fields deleted
protectedpublic void setGrantedPermissions(Set grantedPermissions) {
this.grantedPermissions = grantedPermissions;
}
}
You can see that:
1) The filename contains the CONCATENATION of the meta attributes and superclass name.
2) The package declaration contains the exact same conctatenation.
3) The scope of the setGrantedPermissions method contains the CONCATENATION of the
scope-set values.
I strongly believe that the root bug is related to the following method in
org.hibernate.tool.hbm2x.MetaAttributeHelper.java:
public static String getMetaAsString(org.hibernate.mapping.MetaAttribute c) {
return c==null?"":getMetaAsString(c.getValues() );
}
I don't know exactly what the collection of values of a MetaAttribute is, but I am
fairly convinced that it is the sequence of values defined up the inheritance chain. And
I am *quite* sure that getMetaAsString(Collection meta, String separator) concatenates all
the meta values together, which is exactly the behavior that is causing all these bugs.
Hibernate Tools can't go to 3.2.0GA until these issues are fixed. I will be getting
the code from Subversion and patching it myself (hackishly) on Sunday; I'll upload
details of my fix then, along with a better test case in a properly runnable
self-contained zip.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira