-->
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.  [ 3 posts ] 
Author Message
 Post subject: hbm2java not generating minimal constructor
PostPosted: Mon Jan 03, 2011 11:46 am 
Newbie

Joined: Thu Oct 23, 2003 8:19 am
Posts: 14
Location: Tampa, FL USA
I only seem to get a no arg constructor and a full arg constructor. I would like to have the "minimal constructor" additionally generated with just the id as the only constructor.

I'm using Hibernate-Tools 3.2.3.GA

I'm using the maven ant run task in order to execute an hbm2java like this:

Code:
<hibernatetool destdir="target/generated-sources/hibernate3">
   <configuration>
      <fileset dir="src/main/resources">
         <include name="**/*.hbm.xml"/>
      </fileset>
   </configuration>
   <hbm2java jdk5="true"/>
</hibernatetool>


and I'm configuring my hbm like this:

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>
    <class name="com.example.Addr" table="ADDR">
      <meta attribute="use-in-tostring">true</meta>
      <meta attribute="use-in-equals">true</meta>
       
        <id name="addrSeq" type="java.lang.Long" unsaved-value="null">
            <column name="ADDR_SEQ" precision="22" scale="0" />
            <generator class="sequence">
               <param name="sequence">ADDR_SEQ</param>
            </generator>
        </id>

        <property name="addrLn1" type="string">
            <column name="ADDR_LN_1" length="100" />
        </property>
   </class>
</hibernate-mapping>


-Steve Maring


Top
 Profile  
 
 Post subject: Re: hbm2java not generating minimal constructor
PostPosted: Mon Jan 03, 2011 11:56 am 
Newbie

Joined: Thu Oct 23, 2003 8:19 am
Posts: 14
Location: Tampa, FL USA
just tried 3.2.4.GA and got the same result. no minimal constructor


Top
 Profile  
 
 Post subject: Re: hbm2java not generating minimal constructor
PostPosted: Tue Jan 04, 2011 2:05 pm 
Senior
Senior

Joined: Fri May 08, 2009 12:27 pm
Posts: 168
Missing default specifications it is.

Hibernate reveng cannot pick up the default values from the database, so you'll have to explicitly specify it in hibernate.reveng.xml, like this:

Code:
    <column name="SOME_NUMERIC_FIELD"> <!-- This one is easy enough -->
      <meta attribute="default-value">BigDecimal.ZERO</meta>
    </column>
    <column name="SOME_DATE_FIELD"> <!-- Date fields suck. Blame the Java standard libs. -->
      <meta attribute="default-value">
        new java.sql.Date (new java.util.GregorianCalendar (9999, 11, 31).getTimeInMillis ())
      </meta>
    </column>
    <column name="USER_TYPE_FIELD" type="com.company.project.usertypes.UserTypeForUserTypeField">
      <!-- Having to write out the fully qualified class name sucks, too. -->
      <!-- This time, blame Hibernate Tools, for not providing a way to specify user type packages. -->
      <meta attribute="default-value">
        UserTypeForUserTypeField.NO
      </meta>
      <!-- UserTypeForUserField happens to be an enum. Hibernate rightly doesn't care in the slightest. -->
    </column>


Automatically inferring the default values would be a bit tricky to implement, it would have to deal with complications such as multi-field attributes, indirect attributes, attributes that live in different tables in inheritance situations, and user types. I'd find it ultra-cool to have it anway, but I guess the Tools team is lacking the manpower and outside contributors are lacking the in-depth Hibernate knowledge.
(Writing a layer that parses the JDBC-provided textual metadata into Java raw values would be classical contributor work, but cranking these raw values into Hibernate entities is too hard to do reliably.)


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