-->
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.  [ 5 posts ] 
Author Message
 Post subject: how hbm2java make tostring method
PostPosted: Mon Mar 06, 2006 8:45 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

We want to create java code and cfg files from database. So we used
[code]

<hibernatetool destdir="${destdir}" >
<jdbcconfiguration
packagename="com.mycomp.entities"
configurationfile="${hibernate.cfg}"

/>
<!--@todo it must generate id, to string, equals and hash-->
<hbm2java jdk5="true" />
<hbm2hbmxml />
[/code]

All works fine. But I want that my generated classes impliment tostring, equals and hash map. What property should I add to <hbm2java> task? Is it supported? I don not want to use Eclipse Plug in, just and task.

I found that when you generate java from hbm2hbmxml u must add some meta tags, but what about java code from database?


Another issue: how can i set the defualt id generator. Should I change the velocity templates?

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 06, 2006 8:35 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
not implmented for reverse engineering. you can customize the templates if you want it know.

btw. implementing equals/hashcode is not safe to do automatically since there is no indication of what is the unique part of an entity (which cannot be the id, see www.hibernate.org/109.html ...)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 5:43 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

Can I change the default generator from <generator class="assigned" /> to some thing in ant task else or I should change template?

Regards,
Alireza Fattahi


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 7:20 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
currently easiest done by implementing a custom reverseengineeringstrategy.

something class

class MyRevEng extends DelegatingReverseEngineeringStrategy {

String getTableIdentiferStrategyName(TableIdentifier t) {
return "native"; //or do some selection depending on the value of t
}
}

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 08, 2006 10:04 am 
Beginner
Beginner

Joined: Mon Jan 24, 2005 11:56 am
Posts: 24
Hi,

For the first issue, I found away:
1) I changed the persistentclass.hbm.vm and add in "use-in-tostring" to it.
<meta attribute="use-in-tostring"> true </meta> you can add other code generator parameters here take a look at http://www.hibernate.org/hib_docs/tools ... degen.html

2) I made ddl to java in a two phases task. First from ddl to hbmxml with jdbcconfiguration configuration, second from hbm to java with configuration. It is as below (hope other find it use full):

Code:
<project name="Hibernate-Tool" default="ddl2hbmxml">
    <property name="sourcedir" value="${basedir}/src"/>
    <property name="targetdir" value="${basedir}/bin"/>
    <property name="librarydir" value="${basedir}/exploded/WEB-INF/lib"/>
    <property name="docdir" value="${basedir}/doc"/>
    <property name="sqlfile" value="${docdir}/dal/Schema.sql"/>
    <property name="hibernate.cfg" value="${basedir}/src/Maps/hibernate.cfg.xml"/>
    <property name="destdir" value="${basedir}/src"/>
    <path id="libraries">
        <fileset dir="${librarydir}">
            <include name="*.jar"/>
        </fileset>
        <pathelement location="${sourcedir}"/>
        <pathelement location="${sourcedir}/Maps/"/>
        <pathelement location="${targetdir}"/>
    </path>
    <target name="ddl2hbmxml" description="db>>cfg">
        <taskdef
                name="hibernatetool"
                classname="org.hibernate.tool.ant.HibernateToolTask"
                classpathref="libraries"/>
        <hibernatetool destdir="${destdir}">
            <jdbcconfiguration
                    packagename="com.bonakdar.dal.entities"
                    configurationfile="${hibernate.cfg}"
                    />
            <hbm2hbmxml/>
            <hbm2cfgxml destdir="${destdir}/Maps"/>
            <!--<hbm2doc destdir="${docdir}/dal"/>-->
        </hibernatetool>
    </target>
    <target name="hbm2java" description="cf>>java" depends="ddl2hbmxml">
        <taskdef
                name="hibernatetool"
                classname="org.hibernate.tool.ant.HibernateToolTask"
                classpathref="libraries"/>
        <hibernatetool destdir="${destdir}">
            <configuration
                    configurationfile="${hibernate.cfg}"
                    />
            <hbm2java jdk5="true"/>
            <hbm2ddl destdir="${docdir}/dal" />
        </hibernatetool>
    </target>
</project>


Regards,
Alireza Fattahi


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