-->
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.  [ 11 posts ] 
Author Message
 Post subject: Forcing java.sql.Date datatype with Hbm2JavaTask
PostPosted: Thu Jul 15, 2004 5:26 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
Does anyone know if it's possible to force the hibernate class generation tool to import java.sql.Date in the resultant class? No matter what I do, the resultant class always imports java.util.Date.

beanUtils bails when I try to do a bean copy/type translation from a HashMap to the hibernate bean when the corresponding field in the Hibernate bean is of type java.util.Date.

Thanks in advance,

Rich


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 1:32 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
use type="java.sql.Date" ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 8:36 am 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
I thought that too, but when I explicitly set the type in the conf file, e.g.

property name="cc_date" column="cc_date" type="java.sql.Date">
<meta attribute="field-description">The visit date.</meta>
</property>


The hibernate tool still puts

import java.util.Date;

at the top of the resultant src file. Dunno.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 9:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
if you are sure - then please make a jira bug for it

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 9:42 am 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
I'll create a simple test to verify and be absolutely sure. (My particular mapping file has a lot of stuff in it).

Thanks for the notes.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 2:37 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
I finally found the time to create a simple test and my first observation was correct. For interest, I included the XML, the java task, and the resultant file below.

Thanks for the input.

XML file:

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>

    <class name = "com.myTest.hibernate.Test" table="test">

        <id name="id" type="int" column="id" unsaved-value="0">
            <meta attribute="scope-set">protected</meta>
            <meta attribute="field-description">prospects primary key</meta>
            <generator class="sequence">
                <param name="sequence">mmseq</param>
            </generator>
        </id>

        <property name="test_field" column="test" type="java.sql.Date" not-null="true"></property>
                                     
    </class>
   
</hibernate-mapping>


Ant Task used to build:

Code:
    <taskdef name         = "hbm2java"
             classname    = "net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
             classpathref = "project.class.path"/>
             
    <target name="codegen" description = "Generate Java source from the O/R mapping files">
   
       <hbm2java output = "src">
           <fileset dir = "src">
               <include name = "**/*.hbm.xml"/>
           </fileset>
      </hbm2java>
         
   </target>


And the resultant file (I only listed the top for brevity). Note that java.util.Date is imported, not java.util.SQL


Code:
package com.myTest.hibernate;

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


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

    /** identifier field */
    private int id;

    /** persistent field */
    private Date test_field;

    /** full constructor */
    public Test(Date test_field) {
        this.test_field = test_field;
    }

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 3:53 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
Hmm, same thing happens with java.sql.Time and java.sql.Timestamp


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 16, 2004 6:49 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
Until I get time to look into this you should be able to override the behavior by supplying <meta attribute="property-type">whateveryouwant</meta>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 18, 2004 5:35 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
Very cool. Didn't know I could do that. Thanks a million.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 18, 2004 5:47 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
That sort of works ...

The type of all the variables has been changed, but the import statement stays the same. So compilation fails due to "cannot resolve symbol". Still, it's much better. Thanks for the tip.

I noticed Gavin posted a comment to the bug report and thought the code generatio tool was working as it should. This is my first stab at using the codegent tool - am I going about it in the wrong way?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 18, 2004 5:57 pm 
Beginner
Beginner

Joined: Sat Dec 20, 2003 5:09 pm
Posts: 38
OK, I'm a dummy. I should of seen <extra-import>. I still get compiler errors using that attribute, but I'm getting closer. I'll play with it.

Thanks again for the comments.


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