-->
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.  [ 12 posts ] 
Author Message
 Post subject: Middlegen+hbm2java adding classname prefix, suffix, extends
PostPosted: Tue Nov 22, 2005 1:55 pm 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Hi,

Task:
Part1: having sql schema, generate mapping files and classes with xdoclet. ...DONE
Part2: add a prefix _AAA and suffix _BBB to each generated class i java files ...ERROR
Part3: make the full constructor didn't appear ...ERROR
Part4: add the "implements BaseDAO" phrase after each class name ...ERROR

I've found some examples, downloaded middlegen and now i have generated some hbms.xml files and .java files.

I use Ant. The problem is with Parts2-4.

Let me show u my ant script: I RUN: ANT CODEGEN
Code:

<target
      name="middlegen"
      description="Run Middlegen"
      unless="middlegen.skip"
      depends="init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present"
   >
      <mkdir dir="${build.gen-src.dir}"/>

      <taskdef
         name="middlegen"
         classname="middlegen.MiddlegenTask"
         classpathref="lib.class.path"
      />

      <middlegen
         appname="${name}"
         prefsdir="${src.dir}"
         gui="${gui}"
         databaseurl="${database.url}"
         initialContextFactory="${java.naming.factory.initial}"
         providerURL="${java.naming.provider.url}"
         datasourceJNDIName="${datasource.jndi.name}"
         driver="${database.driver}"
         username="${database.userid}"
         password="${database.password}"
         schema="${database.schema}"
         catalog="${database.catalog}"
         includeViews="false"
      >

       <hibernate
            destination="${build.gen-src.dir}"
            package="Hbm i klasy"
            genXDocletTags="true"
            javaTypeMapper="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
         
        />
       </middlegen>
 
   </target>

////////////////////////////////////////////////////////////////////////////

<target name="codegen" depends="middlegen">
   <taskdef name="hbm2java"
   classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
   classpathref="lib.class.path"/>
   <hbm2java config="codegen.cfg.xml"
   output="${build.gen-src.dir}/generated/src/">
   <fileset dir="${build.gen-src.dir}">
   <include name="**/*.hbm.xml"/>
   </fileset>
   </hbm2java>
</target>


/////////////////////////////////////////////////////




The codegen.cfg.xml file:
Code:
<codegen>
<meta attribute="implements">org.hibernate.auction.model.Auditable</meta>
     <generate suffix="AAA_" renderer="net.sf.Hibernate.tool.hbm2java.BasicRenderer"/>
     <generate prefix="BBB_" renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"/>
     <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer">
       <param name="do-not-create-constructor">true</param>
     </generate>
   </codegen>


What is wrong???
I only generated successfully the suffixes :(
Code:
<codegen>
    <meta attribute="implements">org.hibernate.auction.model.Auditable</meta>
    <generate renderer="net.sf.hibernate.tool.hbm2java.BasicRenderer"
         suffix="_AMG">
      </generate>
</codegen> 


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 5:18 pm 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
hello anybody ;) where can I search for help if not here?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 22, 2005 8:14 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I don't have the time to look at this but a passing glance made the middlegen Package attribute stand out. Why the spaces ? I would never use spaces in a package name. In anycase, does hbm2java work correcty without trying to customise the output? You need to make sure this stage is operating correctly before combining the pipeline output.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 4:50 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
I don't fully understand -
OK. the package name is now one word and it still doesn't work.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 5:00 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
PS. The hbm2java works correctly as I've said - i have successfully generated classes from hbms but now i want to ad some parameters (suffix, prefix, extends...)


Maybe I should extend the BasicRendere class?

package my.demo.hbm2java;

import net.sf.hibernate.tool.*;

public class MyBasicRenderer extends BasicRenderer { - error , why?. hibernate2.jar and hiberatetools are imported to the project.

}


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 8:06 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
ok. if u don't have time to help me, so I understand, but could u just give some tutorial on how to add class prefix and the word "extends"?
I use hibernate 2.1.8 and tools 2.1.3


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 23, 2005 7:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Please don't expect any of the Hibernate team to be continually monitoring the forums. I generally only check once a day.

As far as controlling Middlegens output.
1) Change the Velcoity scripts to generate the output how ever you need it to be

2) Read the docs (and src) to see there is an option that will help, eg, beansuffix might help you in one your goals.
http://boss.bekk.no/boss/middlegen/plugins/hibernate.html

3) Look at the hbm2java meta data options that may be appropiate.

4) Try to help the readers of the forum understand your problem by providing concise information, eg, the input and output, what is failing and what you would like as the output.


I have kept this reponse general in nature as I really am not sure what it is exactly your trying to do. Hope the above helps you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 24, 2005 8:46 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
....and consider using hibernate 3 and the tools instead if you are just starting using hibernate.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 12:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Max has good advice. Going forward upgrading to H3 (and using the tools) would be a worthy path.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 9:13 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
Thanks!

You've helped me a bit ;)
Firstly I must use hibernate 2.x. And now I have two plugins: maven-hibernate and maven -middlegen.
With middlegen-run in maven i'm able to generate my own hbms !! :)
But still... I have to generate classes with xdoclet 1 using MAVEN.
I thought that in maven:
<attainGoal name="hibernate:code-generation"/>
would do it... I don't see any new java files although the process is succesfull. Maybe it isn't for this purpose?

So? Hbm2java?
But how to use it in MAVEN?

In ANT it works: (but i don't have any idea how to write such simple thing in maven do u?)

<target name="codegen">
<taskdef name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="lib.class.path"/>
<hbm2java config="codegen.cfg.xml"
output="${build.gen-src.dir}">
<fileset dir="${build.gen-src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 25, 2005 9:39 am 
Beginner
Beginner

Joined: Tue Nov 22, 2005 6:55 am
Posts: 41
if hibernate:code-generation is good for it, please tell me from where by default it takes the hbms and where it generate classes?
It is alway successfull but i don't have new files.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Nov 26, 2005 1:18 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I cannot help with Maven as I have never used it. I only use Ant. In this case, the directories are detailed in the Ant task script for hbm2java.


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