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.  [ 7 posts ] 
Author Message
 Post subject: component mapping and hbm2java pojo generation problems
PostPosted: Tue Jun 07, 2005 9:43 pm 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.05

I have the following component mapping and am using hbm2java which I downloaded from the jboss site. This is the latest version i've been able to find. The java code that is generated from this is not what I would expect. It appears to be overriding the user class properties / methods with those contained within the address component mapping. Is there something obvious i'm missing here ?


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 package="au.com.groupware.model">

    <class name="User" table="Users">
       <meta attribute="generated-class">au.com.groupware.model.UserAbstract</meta>
      <meta attribute="scope-class" inherit="false">public abstract</meta>
   
         <id name="id" column="UserId" type="string" length="50">
            <generator class="assigned" />
        </id>
      <version name="version" column="Version" type="integer" unsaved-value="null" />
      <property name="firstName" column="FirstName" type="string"  not-null="true" length="100" />
      <property name="lastName" column="LastName" type="string"  not-null="true" length="100" />
      <property name="password" column="Password" type="string"  not-null="true" length="50" />
      <property name="enabled" column="Enabled" type="boolean" not-null="true" />
      <property name="email" column="Email" type="string" not-null="true" length="255" />
      <property name="phone" column="Phone" type="string" length="20" />
      <property name="mobile" column="Mobile" type="string" length="20" />
      <property name="fax" column="Fax" type="string" length="20" />
      
      <component name="address" class="au.com.groupware.model.Address">
         <property name="streetAddress1" type="string" column="StreetAddress1" not-null="true" />
         <property name="streetAddress2" type="string" column="StreetAddress2" />
         <property name="city" type="string" column="City" not-null="true" />
         <property name="postcode" type="string" column="postcode" not-null="true" />   
         <many-to-one name="state" class="au.com.groupware.model.State" column="StateId"
            foreign-key="FK_Address_State" not-null="true" />
      </component>
      
      <set name="userRoles" table="UserRole" lazy="true" >
         <key column="UserId" />
         <composite-element class="au.com.groupware.model.UserRole">
            <parent name="user" />
            <many-to-one name="role"
                  class="au.com.groupware.model.Role" 
                  column="RoleId"
                  not-null="true" foreign-key="FK_UserRole_Role" />                        
            <property name="dateModified" column="DateModified" type="date" />
         </composite-element>
      </set>

    </class>
   
</hibernate-mapping>




Code:
package au.com.groupware.model;


/**
* UserAbstract generated by hbm2java
*/
public class UserAbstract  implements java.io.Serializable {

    // Fields   

private java.lang.String streetAddress1;
private java.lang.String streetAddress2;
private java.lang.String city;
private java.lang.String postcode;
private au.com.groupware.model.State state;


    // Constructors

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

    // Property accessors
    /**
   
    */
   
    public java.lang.String getStreetAddress1 () {
        return this.streetAddress1;
    }
   
   public void setStreetAddress1 (java.lang.String streetAddress1) {
        this.streetAddress1 = streetAddress1;
    }
    /**
   
    */
   
    public java.lang.String getStreetAddress2 () {
        return this.streetAddress2;
    }
   
   public void setStreetAddress2 (java.lang.String streetAddress2) {
        this.streetAddress2 = streetAddress2;
    }
    /**
   
    */
   
    public java.lang.String getCity () {
        return this.city;
    }
   
   public void setCity (java.lang.String city) {
        this.city = city;
    }
    /**
   
    */
   
    public java.lang.String getPostcode () {
        return this.postcode;
    }
   
   public void setPostcode (java.lang.String postcode) {
        this.postcode = postcode;
    }
    /**
   
    */
   
    public au.com.groupware.model.State getState () {
        return this.state;
    }
   
   public void setState (au.com.groupware.model.State state) {
        this.state = state;
    }




}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 1:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmm - that should not happen! put it in jira

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 08, 2005 2:36 am 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Thanks Max. I've added this to the Jira.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 13, 2005 11:55 pm 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Max, I finally downloaded the newest alpha 4 release of the Hibernate Tools and am still experiencing this problem. You mentioned in the Jira that you could not reproduce my problem in CVS. I'm guessing that by the dates on the latest release and your last post that I have the code you would have tested this on.

Is there something else funny going on with my mapping above maybe because I can't figure out what is wrong ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 12:29 am 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
rmonie,

did you ever sort this out?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 1:08 am 
Newbie

Joined: Tue Jun 07, 2005 10:45 pm
Posts: 15
Location: Sydney
Found it. Need to add inherit="false" to all <meta> attributes for the top level class, otherwise, the component inherits, amongst others, the generated class attribute and overwrites it.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 15, 2005 10:36 am 
Newbie

Joined: Tue May 24, 2005 7:08 pm
Posts: 17
Location: Melbourne
Thanks for posting this solution. I'll try it out when I get a chance. I never did sort it out and have been manually adjusting my mapping files since. Luckily I've only had to make small changes to the data model here and there.


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