-->
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: hbm2java MappingException when generating subset of files.
PostPosted: Thu Feb 23, 2006 6:48 pm 
Newbie

Joined: Mon Jul 25, 2005 4:35 pm
Posts: 9
I'm using hbm2java ant task from HibernateTools 3.1.0 beta 4.

I have some hibernate objects that reference other hibernate objects that I do not want to generate. However, this isn't working.

My ant task is as follows with hibernatetool setup with a class path to include all needed files.

If I do the following, I get an error (notice separate project's Hbm files referenced in classpath).

Code:
    <target name="codegen >
        <hibernatetool  destdir="srcgen">
          <classpath>
            <dirset dir="../otherhibproj/src"/>
          </classpath>
          <configuration>
            <fileset dir="src">
                <include name="**/*Hbm.xml"/>
            </fileset>
          </configuration>
          <hbm2java jdk5="false" ejb3="false"/>
        </hibernatetool>
    </target>


[hibernatetool] BUILD FAILED: org.hibernate.MappingException: An association from the table CODES refers to an unmapped class: com.otherhibproj.hib.ObjectImpl
BUILD FAILED:

If, I however move the referenced Hbm file into the configuration, it works.

Code:
    <target name="codegen >
        <hibernatetool  destdir="srcgen">
          <configuration>
            <fileset dir="src">
                <include name="**/*Hbm.xml"/>
            </fileset>
            <fileset dir="../otherhibproj/src">
                <include name="**/*Hbm.xml"/>
            </fileset>
          </configuration>
          <hbm2java jdk5="false" ejb3="false"/>
        </hibernatetool>
    </target>



I have tried a variety of different methods of including the referenced Hbm file in the classpath, but to no avail. Am I doing something wrong, or does hbm2java require you to rebuild ALL java objects.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 7:55 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the model we load need to be complete - thus everything that is connected needs to be loaded together.

If you only want to generate "parts" of the code the best current (and always future) way is to generate the code into a seperate dir, delete everything besides the classes you need and copy it back....

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject: feature should be added to allow for sub generation
PostPosted: Fri Feb 24, 2006 11:33 am 
Newbie

Joined: Mon Jul 25, 2005 4:35 pm
Posts: 9
While I understand that the entire model needs to be in place for the generation, I disgree that it should assume you want all .java files generated (BTW: hbm2java in hibernate 2 doesn't require the entire model, and it has worked rather well for us this way).

I realized the workaround as well (generate everything and delete what I don't want) but I don't agree that hbm2java should assume this is "acceptible". A simple setting could be added to the task to allow for regeneration only on a given set of Hbm files.

Even if I use the "delete" approach, I'm waisting a lot of time regenerating classes I will only end up deleting. As I get more and more Hbm files in my project, this just is more clumbersome.

I will put this in as a feature request into JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 24, 2006 12:12 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
I know Hibernate 2 tools supported it (I wrote it), but it had other flaws which all vanished when we started using the h3 core model.

And how much time is this model generation actually taking for you ?!
Adding a feature for this with something that is easily handled in ant is not something i do for a few sec speed up.

And please note that it cannot be the hbm files that you use to limit it with since the java exporter does not know from which hbm.xml file the mapping comes.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sat Feb 25, 2006 12:56 pm 
Newbie

Joined: Mon Jul 25, 2005 4:35 pm
Posts: 9
I think I can come up with solutions using ant tasks around the hbm2java tool as you suggest.

I have a mix of code where some code isn't to be generanted, along with the following:

Code:
                           A
                           |
                         AGen
                        |    |
                   A1Impl  A2Impl

  A1ImplHbm.xml -> generate AGen (instead of Impl)
  A2ImplHbm.xml -> generate AGen (instead of Impl)



I generated A2ImplHbm.xml from A1ImplHbm.xml to insure properites are identical (just different table reference and a few other minor differences).


I think with the above code I can just have A2ImplHbm generate a AGenDummy or something and not copy it over. The trick becomes if there are inner components shared between A1Impl and A2Impl and they both get generated.

I know the above scenario is an unusual exception but we have two identical tables and we want to have hibernate objects for both of them but treat them as the same classes. While we could have a A1Gen and A2Gen having the generated class shared reduced some code duplication in other areas.

Anyway, this does give an example to why this would be of interested to me, but I think with some more tweaking, I can get it to work out.

Thanks,

Neil


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.