-->
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.  [ 6 posts ] 
Author Message
 Post subject: Created Contructor not correct
PostPosted: Thu Mar 30, 2006 5:37 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
Hibernate version:3.1
Hibernate Tools version:3.1.0 beta4a
Name and version of the database:Oracle 10g


Hi,

i generate .hbm.xml and POJOs with the Hibernate Tools via reveng.

The created POJO is not correct - in the full constructor is one field missing (the VERSION field).

Code:
/**
* AcVersGroup generated by hbm2java
*/

public class AcVersGroup  implements java.io.Serializable {


    // Fields   

     private String versGroupId;
     private String version;
     private String groupName;


    // Constructors

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

   /** minimal constructor */
    public AcVersGroup(String versGroupId) {
        this.versGroupId = versGroupId;
    }
   
    /** full constructor */
    public AcVersGroup(String versGroupId, String groupName) {
        this.versGroupId = versGroupId;
        this.groupName = groupName;
    }
   

   
    // Property accessors

    public String getVersGroupId() {
        return this.versGroupId;
    }
   
    public void setVersGroupId(String versGroupId) {
        this.versGroupId = versGroupId;
    }

    public String getVersion() {
        return this.version;
    }
   
    public void setVersion(String version) {
        this.version = version;
    }

    public String getGroupName() {
        return this.groupName;
    }
   
    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }
   








}


The generated mapping file has not the element property for the field VERSION, it uses the element version. Is this a problem with the name version???

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">
<!-- Generated 30.03.2006 11:15:34 by Hibernate Tools 3.1.0 beta3 -->
<hibernate-mapping>
    <class name="mywork.pojo.AcVersGroup" table="AC_VERS_GROUP">
        <id name="versGroupId" type="string">
            <column name="VERS_GROUP_ID" length="10" />
            <generator class="assigned" />
        </id>
        <version name="version" type="string">
            <column name="VERSION" length="10" />
        </version>
        <property name="groupName" type="string">
            <column name="GROUP_NAME" length="40" />
        </property>
    </class>
</hibernate-mapping>


Whats wrong, how can i fix it?


Thanks for help,

Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:42 am 
Newbie

Joined: Wed Mar 01, 2006 4:14 am
Posts: 16
some tips

if you property is called version you don't need to add column name = version

you don't need to add type="string" as it uses the same type of the property, in your case java.lang.String or when you use a Long or Integer: java.lang.Long, java.lang.Integer by looking at the property (getter)

use a Long or Integer as version

set the setter and getter for version to protected (private) and use access="field"

version is used internally and you should not care anywhere when using an object so a contructor with a version is not needed, hibernate will use version by setter/getter or the property directly when using access="field"


---------------------------------------------------------------


private Long version;

protected Long getVersion() {...}
protected void setVersion(Long version) {...}


---------------------------------------------------------------

<version name="version" />


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 5:54 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
The VERSION field is a DB field, by the reveng the normally PROPERTY-Element is mapped as a VERSION-Element.

Code:
CREATE TABLE AC_VERS_GROUP (
  VERS_GROUP_ID  VARCHAR2(10),
  GROUP_NAME     VARCHAR2(40),
  VERSION        VARCHAR2(10)
           CONSTRAINT pk_ac_vers_group PRIMARY KEY (vers_group_id)
);



Michael


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 7:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
version is not included in the constructor because it is a <version>.

a column named VERSION is automatically detected as a <version> column (it should probably be an option, but right now it is automatic).

If you don't want that behavior you can write a custom reveng strategy which implement a method that tells us to ignore all columns:


class RevStr extends DelegatingReverseEngineeringStrategy {

public RevStr(ReverseEngineeringStrategy delegate) {
super(delegate);
}

public Boolean useColumnForOptimisticLock(
TableIdentifier identifier, String column
) {
return Boolean.FALSE;
}
}

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 30, 2006 8:43 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
Yeah, this fixed my problem.

Thank you Max!


Michael


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 25, 2006 9:34 am 
Newbie

Joined: Thu Mar 30, 2006 4:53 am
Posts: 12
I changed to Hibernate Tools 3.1.0 beta 5 and now the workaround doen't work anymore.

I correct the methods return-type from old Boolean to new boolean.

Now i have the same problem as before.


Thanx for help

Michael


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