-->
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.  [ 4 posts ] 
Author Message
 Post subject: meta attribute of scope-get/set & inherit bug?
PostPosted: Thu Mar 16, 2006 2:37 pm 
Newbie

Joined: Mon Jul 25, 2005 4:35 pm
Posts: 9
Hibernate 3.1.2
Hibernate Toolage 3.1 beta 4

I'm trying to setup a default scope for the getters and setters by plaing the meta attribute at the class level (see example Hbm file). This is inherited to the properites. I have some properites that will override this behavior by setting it differently within the property. However, when this is done, the scope information gets messed up (i.e. 'privatepublicpublic') as shown in the generate .java file.

In hibernate2, this worked w/out problems.

Thanks,

Neil


Code:
<?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>


Code:
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;
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 3:48 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
are you completely sure about this ?

If i look in the code for the tools for version 2 we also here appended all the meta elements so if more than one is specified you get one long messed up string.

that said I could probably be convinced about introducing this behavior in the hibernate3 tools if the sequence of meta's in our metamodel corresponds to the sequence in the mappings...i'm not sure that is always the case.

Anyhow, please let me know if you *verify* that the behavior you describe is truely working in hibernate tools 2.1....i wan't to see the input and output - thanks.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: hiberante 2 result
PostPosted: Fri Mar 17, 2006 12:33 pm 
Newbie

Joined: Mon Jul 25, 2005 4:35 pm
Posts: 9
The version of hibernate-tools.jar I used with hibernate2 was 2.1.3 as shown from the readme.txt file in the jar file.

Code:
Hibernate Tools - Tools for Hibernate
=====================================
version 2.1.3, 18. November 2004


The Hbm.xml file is identical to the one in the original post except for the 2.0/3.0 dtd change.
Code:
<?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>


Here is the output from 'hbm2java' with hibernate 2.
Code:
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();
    }

}



Since the work around is fairly easy (don't use set-scope at the class level), this isn't a big concern for me. I just thought you would want to be aware of it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 17, 2006 12:48 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm...could you please put this in a jira so i can take a look at it once i get time - thanks!

_________________
Max
Don't forget to rate


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