-->
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: POJO generation
PostPosted: Thu Apr 26, 2007 12:08 pm 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
Hi all,

I have very specific problem.
I am using Maven (hibertnate3:hbm2java)
to do some reverse engineering.

Everything looks OK but I don't want to use
.hbm.xml e.g. I need to define classes somewhere else.

Up to now as defined in .xmb.xml it continuously ask for the java
files to generate POJO's but as described above I don't want to generate them
in this way. Is there some work around for this problem (except ANT)

P.S. I need to use Maven for Code generation, not the Eclipse.

Thanks,
Ned


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 12:42 pm 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
I think everyone here would only recomened using ant or the eclipse plug in to do your reverse engerneared pojo generation. personaly i'd recomend and ant script like this:
Code:
<project name="goFurtherTools" basedir="../" default="hibernateCodeGen">
   <property name="tools.dir" value="tools" />
   <property name="src.dir" value="src" />
   <property name="web.dir" value="web" />
   <property name="test.src" value="test" />
   <property name="lib.dir" value="${web.dir}/lib" />
   <property name="build.dir" value="build" />
   <property name="test.dir" value="${build.dir}/test" />
   <property name="webapp.name" value="goFurther" />
   <property name="gen.dir" value="gen" />

   <property environment="env" />
   <property name="ant.home" value="${env.ANT_HOME}" />
   <property name="tomcat.home" value="${env.CATALINA_HOME}" />
   <property name="tomcat.lib.dir" value="${tomcat.home}/common/lib" />

   <path id="classpath">
      <pathelement path="${java.class.path}/" />
      <pathelement path="${build.dir}/classes" />
      <pathelement path="${build.dir}/test/classes" />
      <fileset dir="${lib.dir}">
         <include name="**/*.jar" />
      </fileset>
   </path>

   <path id="toolslib">
      <path location="lib/hibernate-tools.jar" />
      <path location="lib/hibernate3.jar" />
      <path location="lib/freemarker.jar" />
      <path location="${jdbc.driver.jar}" />
   </path>

   <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="toolslib" />

   <target name="hibernateCodeGen">
      <copy todir="${build.dir}/classes" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/config">
            <include name="*.*" />
         </fileset>
      </copy>

      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain/data">
            <include name="*.*" />
         </fileset>
      </delete>
      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/dao/base/hibernate">
            <include name="*.*" />
         </fileset>
      </delete>
      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/config">
            <include name="*.*" />
         </fileset>
      </delete>
      <delete dir="${tools.dir}/hibernate/generated"/>

      <hibernatetool
         destdir="${tools.dir}/hibernate/generated"
         templatepath="${tools.dir}/hibernate/templates"
      >
         <classpath>
            <path location="${build.dir}/classes" />
            <path location="${basedir}/lib" />
         </classpath>
         <jdbcconfiguration
            packagename="uk.ltd.goFurther.domain"
            propertyfile="${tools.dir}/hibernate/config/hibernate.properties"
            reversestrategy="uk.ltd.goFurther.tools.hibernate.reverseEngineering.CustomReverseEngineeringStrategy"
            revengfile="${tools.dir}/hibernate/config/hibernate.reveng.xml"
         />
         <hbm2hbmxml />
      </hibernatetool>

      <hibernatetool
         destdir="${tools.dir}/hibernate/generated"
         templatepath="${tools.dir}/hibernate/templates"
      >
         <classpath>
            <path location="${build.dir}/classes" />
            <path location="${basedir}/lib" />
         </classpath>
         <jdbcconfiguration
            packagename="uk.ltd.goFurther.domain.data"
            propertyfile="${tools.dir}/hibernate/config/hibernate.properties"
            reversestrategy="uk.ltd.goFurther.tools.hibernate.reverseEngineering.CustomReverseEngineeringStrategy"
            revengfile="${tools.dir}/hibernate/config/hibernate.reveng.xml"
         />
         <hbm2java />
      </hibernatetool>

      <copy todir="${tools.dir}/hibernate/generated/config" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain">
            <include name="*.hbm.xml" />
         </fileset>
      </copy>
      <delete>
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain">
            <include name="*.hbm.xml" />
         </fileset>
      </delete>

      <mkdir dir="${tools.dir}/hibernate/generated/tmp"/>

      <copy todir="${tools.dir}/hibernate/generated/tmp" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain/data">
            <include name="*.*" />
         </fileset>
         <globmapper from="*.java" to="*Data.java"/>
      </copy>
      <delete>
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain/data">
            <include name="*.java" />
         </fileset>
      </delete>
      <copy todir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain/data" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/tmp">
            <include name="*.java" />
         </fileset>
      </copy>
      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/tmp">
            <include name="*.*" />
         </fileset>
      </delete>

      <hibernatetool
         destdir="${tools.dir}/hibernate/generated"
         templatepath="${tools.dir}/hibernate/templates"
      >
         <classpath>
            <path location="${build.dir}/classes" />
            <path location="${basedir}/lib" />
         </classpath>
         <jdbcconfiguration
            packagename="uk.ltd.goFurther.dao.base.hibernate"
            propertyfile="${tools.dir}/hibernate/config/hibernate.properties"
            reversestrategy="uk.ltd.goFurther.tools.hibernate.reverseEngineering.CustomReverseEngineeringStrategy"
            revengfile="${tools.dir}/hibernate/config/hibernate.reveng.xml"
         />
         <hbm2dao />
      </hibernatetool>
      <copy todir="${tools.dir}/hibernate/generated/tmp" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/dao/base/hibernate">
            <include name="*.*" />
         </fileset>
         <globmapper from="*Home.java" to="*DAOBaseHibernate.java"/>
      </copy>
      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/dao/base/hibernate">
            <include name="*.*" />
         </fileset>
      </delete>
      <copy todir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/dao/base/hibernate" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/tmp">
            <include name="*.*" />
         </fileset>
      </copy>
      <delete failonerror="false">
         <fileset dir="${tools.dir}/hibernate/generated/tmp">
            <include name="*.*" />
         </fileset>
      </delete>
      <delete dir="${tools.dir}/hibernate/generated/tmp"/>
      
      <delete failonerror="false">
         <fileset dir="${src.dir}/java/uk/ltd/goFurther/dao/base/hibernate">
            <include name="*.*" />
         </fileset>
      </delete>      
      <delete failonerror="false">
         <fileset dir="${src.dir}/java/uk/ltd/goFurther/domain/data">
            <include name="*.*" />
         </fileset>
      </delete>      
      <delete failonerror="false">
         <fileset dir="${src.dir}/java/uk/ltd/goFurther/domain/conf">
            <include name="*.*" />
         </fileset>
      </delete>      

      <copy todir="${src.dir}/java/uk/ltd/goFurther/dao/base/hibernate" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/dao/base/hibernate">
            <include name="*.*" />
         </fileset>
      </copy>
      <copy todir="${src.dir}/java/uk/ltd/goFurther/domain/data" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/uk/ltd/goFurther/domain/data">
            <include name="*.*" />
         </fileset>
      </copy>
      <copy todir="${src.dir}/java/uk/ltd/goFurther/domain/conf" includeemptydirs="false" overwrite="true">
         <fileset dir="${tools.dir}/hibernate/generated/config">
            <include name="*.*" />
         </fileset>
      </copy>
   </target>
</project>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 26, 2007 1:55 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes - i recommend the ant version.

I got an email from the maven guy who apparently did the maven port but I haven't had time looking into what it does (besides it is not actually seem to be doing what I want a maven port to do ;) I shuold get around looking at it.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Pojo Generation
PostPosted: Fri Apr 27, 2007 3:33 am 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
Thanks

Max if you have some interesting news please reply.

As I wrote I don't want to prepare (pregenerate) pojos in the way .xbm.xml does. Rather I need solution that will just define tables, columns, target directory and/or any other needed parameters and generate pojos there.

Regards,
Ned


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 5:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
sorry - i don't understand your question ?!

you don't want mapping files nor classes ?!

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: POJO Generation
PostPosted: Fri Apr 27, 2007 6:16 am 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
OK, here is my code

if
my Sample.xbm.xsl
looks like:

<?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="clpath.Sample" table="Sampletable">
<meta attribute="extends">clpath.NewPOJO</meta>
<meta attribute="class-description">
Pojo for entity Sample.
</meta>

<id name="id" column="ID">
<meta attribute="field-description">Primary Key</meta>
<generator class="sequence">
<param name="sequence">Sample_SEQ</param>
</generator>
</id>


</class>

</hibernate-mapping>

Maven would always complain that can not find ID (column in Sample.java)


If I don't create clpath.Sample.java with integer ID (MANUALY)
my new clpath.Sample.java (Pojo) with EJB annotation will be not generated.

I am searching to do the same without making Sample.java with ID

The same class called EchoMessage in Hibernate sample looks like:



package com.genuitec.hibernate;
// Generated by MyEclipse - Hibernate Tools



/**
* EchoMessage generated by MyEclipse - Hibernate Tools
*/
public class EchoMessage extends AbstractEchoMessage implements java.io.Serializable {

// Constructors

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

/** minimal constructor */
public EchoMessage(Long id) {
super(id);
}

/** full constructor */
public EchoMessage(Long id, String msg) {
super(id, msg);
}

}


OR

If I am wrong should this file be generated by eclipse somehow in the some previous step?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 6:22 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
You haven't specified a type for the id; so hard for the tooling to generate the correct type ;)

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: Type for ID
PostPosted: Fri Apr 27, 2007 6:27 am 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
What it should be exactly??


Top
 Profile  
 
 Post subject: ID
PostPosted: Fri Apr 27, 2007 6:35 am 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
I guess something like:

<id name="id" type="long" column="id">


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 6:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
yes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: ID
PostPosted: Fri Apr 27, 2007 7:10 am 
Newbie

Joined: Thu Apr 26, 2007 11:48 am
Posts: 6
Thanks, that really helped!


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.