-->
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.  [ 4 posts ] 
Author Message
 Post subject: excluding a component class from hbm2java
PostPosted: Tue Jun 03, 2008 11:44 am 
Newbie

Joined: Mon Mar 05, 2007 2:25 am
Posts: 12
Ok, no idea if this has come up before but I can't find it...

What I want is this,

I have a hbm mapping file with a few properties and a component. The properties map to single columns in my table and the component maps to 3 columns in my table. Now I want to link the component to a class from a library I downloaded from the net. Ok, all this works like it should. Problems start however when I want to use hibernate tools to generate the Pojo. The classes are generated without a problem. The only thing is that the component class is also generated. This I do not want because I already have this class in a jar file.

Is there a way to have the main class in a hbm generated by tools, but to exclude a component class from generation? I tried editting the ftl templates to this end, and I can make them so they don't create any ava code for the component, but still, the java file IS generated...

My HBM looks 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 package="com.ractoc.flux.mapper.persistence">

   <class name="MapObjectDO" table="MAP_OBJECTS">

      <meta attribute="generated-class" inherit="false">
         com.ractoc.flux.persistence.base.MapObjectBaseDO
      </meta>
      <meta attribute="scope-class" inherit="true">
         public abstract
      </meta>

      <id name="id" column="OBJ_ID" type="long" length="18">
         <generator class="native">
            <param name="sequence">SEQ_MAP_OBJECTS</param>
         </generator>
      </id>
      <version type="timestamp" name="softlock"
         column="PEQ_SOFTLOCK_TS" unsaved-value="undefined"
         generated="never">
         <meta attribute="property-type" inherit="true">
            java.sql.Timestamp
         </meta>
      </version>

      <property name="name" column="OBJ_NAME" type="string"
         not-null="true" length="12" unique-key="MAP_OBJECTS_NAME_TYPE_UK" />
      <property name="description" column="OBJ_DESC" type="string"
         not-null="true" length="250" />
      <property name="code" column="OBJ_CODE" type="string"
         not-null="true" length="8" unique="true" />
      <component name="location" class="com.jme.math.Vector3f" >   
      <property name="x" column="OBJ_LOC_X" type="float">
            <meta attribute="gen-property">false</meta>
         </property>
         <property name="y" column="OBJ_LOC_Y" type="float">
            <meta attribute="gen-property">false</meta>
         </property>
         <property name="z" column="OBJ_LOC_Z" type="float">
            <meta attribute="gen-property">false</meta>
         </property>
      </component>   </class>


</hibernate-mapping>



In this hbm, the com.jme.math.Vector3f is a class from an external jar. This jar is presento n the classpath of the ant task I'm using to create the java files.
Mark


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 3:17 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
we dont have a complete fine control over it in the level of code generation...but here is some workarounds:

1) use for-each attribute to say you only want to run through "entity"'es this will then only generate entities and not components/values.

2) generate into a seperate src dir and only copy over the things you want excluding the redundant java file

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 04, 2008 2:01 pm 
Newbie

Joined: Mon Mar 05, 2007 2:25 am
Posts: 12
Ok, I got it to work with a slight variation on the second workaround.
I added the following to the component in my hbm file:
<meta attribute="generated-class" inherit="false">remove.Hbm2JavaRemoveThisClass</meta>

and this I added to the end of the hbm2java ant task:
<delete dir="src/remove"/>
what this does is create a dummy class in a dummy package called remove. after the java files are generated, the delete ant call removes this dummy package from the filesystem.

Seems like a lot of work, but works great. And the best thing is, if I have more classes that don't need to be generated, I can just generate them in the same remove package and they will automatically cleaned up after the hbm2java is completed.

Mark


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 05, 2008 8:02 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
that would work too ;)

_________________
Max
Don't forget to rate


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