meta attribute of scope-get/set & inherit bug

Description

An inhertiable class level meta attribute of scope-get and scope-set cannot be overridden within a property. Instead some string concat is being applied. This is different behavior than with hibernate tools 2.1.3 and it is a potential bug (or at least a change of behavior).

Hibernate 3 Mapping File

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping package="com.hibernate">
<class mutable="true" lazy="false" name="com.hibernate.Test" table="TEST">
<meta attribute="scope-get">private</meta>
<meta attribute="scope-set">private</meta>
<id name="id" column="ID" type="long">
<generator class="assigned" />
</id>
<property name="col1" column="COL1" type="java.lang.String">
<meta attribute="scope-get">public</meta>
</property>
<property name="col2" column="COL2" type="java.lang.String">
<meta attribute="scope-set"></meta>
<meta attribute="scope-get">public</meta>
</property>
<property name="col3" column="COL3" type="java.lang.String">
</property>
<property name="col4" column="COL4" type="java.lang.String">
</property>
</class>
</hibernate-mapping>

Hibernate 3 Generated File

package com.hibernate;
// Generated Mar 16, 2006 10:00:19 AM by Hibernate Tools 3.1.0.beta4

/**

  • Test generated by hbm2java
    */

public class Test implements java.io.Serializable {
// Fields

private long id;
private String col1;
private String col2;
private String col3;
private String col4;

// Constructors

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

/** minimal constructor */
public Test(long id) {
this.id = id;
}

/** full constructor */
public Test(long id, String col1, String col2, String col3, String col4) {
this.id = id;
this.col1 = col1;
this.col2 = col2;
this.col3 = col3;
this.col4 = col4;
}

// Property accessors

privatepublicpublic long getId() {
return this.id;
}

private void setId(long id) {
this.id = id;
}

privatepublicpublic String getCol1() {
return this.col1;
}

private void setCol1(String col1) {
this.col1 = col1;
}

privatepublicpublic String getCol2() {
return this.col2;
}

private void setCol2(String col2) {
this.col2 = col2;
}

privatepublicpublic String getCol3() {
return this.col3;
}

private void setCol3(String col3) {
this.col3 = col3;
}

privatepublicpublic String getCol4() {
return this.col4;
}

private void setCol4(String col4) {
this.col4 = col4;
}
}

Hibernate 2 Mapping File

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping package="com.hibernate">
<class mutable="true" lazy="false" name="com.hibernate.Test" table="TEST">
<meta attribute="scope-get">private</meta>
<meta attribute="scope-set">private</meta>
<id name="id" column="ID" type="long">
<generator class="assigned" />
</id>
<property name="col1" column="COL1" type="java.lang.String">
<meta attribute="scope-get">public</meta>
</property>
<property name="col2" column="COL2" type="java.lang.String">
<meta attribute="scope-set"></meta>
<meta attribute="scope-get">public</meta>
</property>
<property name="col3" column="COL3" type="java.lang.String">
</property>
<property name="col4" column="COL4" type="java.lang.String">
</property>
</class>
</hibernate-mapping>

Hibernate 2 Generated File

package com.hibernate;

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

/** @author Hibernate CodeGenerator */
public class Test implements Serializable {

/** identifier field */
private Long id;

/** nullable persistent field */
private String col1;

/** nullable persistent field */
private String col2;

/** nullable persistent field */
private String col3;

/** nullable persistent field */
private String col4;

/** full constructor */
public Test(Long id, String col1, String col2, String col3, String col4) {
this.id = id;
this.col1 = col1;
this.col2 = col2;
this.col3 = col3;
this.col4 = col4;
}

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

/** minimal constructor */
public Test(Long id) {
this.id = id;
}

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

private void setId(Long id) {
this.id = id;
}

public String getCol1() {
return this.col1;
}

private void setCol1(String col1) {
this.col1 = col1;
}

public String getCol2() {
return this.col2;
}

void setCol2(String col2) {
this.col2 = col2;
}

private String getCol3() {
return this.col3;
}

private void setCol3(String col3) {
this.col3 = col3;
}

private String getCol4() {
return this.col4;
}

private void setCol4(String col4) {
this.col4 = col4;
}

public String toString() {
return new ToStringBuilder(this)
.append("id", getId())
.toString();
}

}

see also forum topic http://forum.hibernate.org/viewtopic.php?t=956894#2296725

Environment

Hiberante 3.1.2 Hibernate Tools 3.1 beta 4

Activity

Show:

Max Rydahl Andersen October 30, 2006 at 6:19 PM

fixed - requires Hibernate Core 3.2.1

Rob Jellinghaus October 27, 2006 at 11:55 PM

Max, please consider this verified. I have the exact same problem. Here's a fragment of a mapping:

<hibernate-mapping default-lazy="false">

<class name="com.nimblefish.core.domain.configuration.Configuration">
<meta attribute="generated-class">com.nimblefish.core.domain.generated.ConfigurationGen</meta>
<meta attribute="scope-class" inherit="false">public abstract</meta>
<meta attribute="scope-set">protected</meta>
...
<!-- all configurations have codes, really -->
<property name="code" type="string">
<meta attribute="use-in-tostring">true</meta>
<meta attribute="scope-set">public</meta>
</property>
...

And here's a fragment of the POJO created by hibernatetool's hbm2java:

package com.nimblefish.core.domain.generated;
// Generated Oct 27, 2006 2:43:27 PM by Hibernate Tools 3.2.0.beta8
import com.nimblefish.core.domain.configuration.FrozenConfigurationHolder;
import com.nimblefish.core.domain.engine.Engine;
import java.util.HashMap;
import java.util.Map;
/**

  • ConfigurationGen generated by hbm2java
    */
    public abstract class ConfigurationGen implements java.io.Serializable {
    ...
    protectedpublic void setCode(String code) {
    this.code = code;
    }

Definitely a bug, and a painful one to fix, since now I have to go through and remove ALL of the <meta attribute="scope-set"> tags on ALL of the classes that override the setter scope for individual fields Please fix it for Hibernate Tools 3.2GA!

Max Rydahl Andersen September 14, 2006 at 7:12 PM

need to evaluate/verify

Fixed

Details

Assignee

Reporter

Bug Testcase Reminder (view)

Bug reports should generally be accompanied by a test case!

Bug Testcase Reminder (edit)

Bug reports should generally be accompanied by a test case!

Participants

Max Rydahl Andersen
Neil Buesing
Rob Jellinghaus

Fix versions

Affects versions

Priority

Created March 17, 2006 at 9:19 PM
Updated October 30, 2006 at 6:19 PM
Resolved October 30, 2006 at 6:19 PM