Details
-
Type:
New Feature
-
Status:
Closed
-
Priority:
Major
-
Resolution: Fixed
-
Affects Version/s: None
-
Fix Version/s: 1.3
-
Component/s: None
-
Labels:None
-
Environment:N/A
-
Number of attachments :8
Description
I have added a feature to my local version of the hibernate plugin which I thought might be worthy of inclusion in a future version.
In the projects I work on there is a need to generate POJOs classes from hibernate hbm files and I have adapted and incorportated an old ant script into our maven-hibernate plugin to do this.
In order to add this goal all you have to do is:
1. Add the following to project.xml:
<dependency>
<groupId>hibernate-extensions</groupId>
<artifactId>hibernate-tools</artifactId>
<version>2.1.2</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>jdom</groupId>
<artifactId>jdom</artifactId>
<version>1.0</version>
<type>jar</type>
</dependency>
2.
Add the following goal to the plugin.jelly
<goal name="hibernate:hbm-code-generation" prereqs="hibernate:init" description="Generate POJOs from hbm files">
<ant:echo>Generating POJOs from hbm files</ant:echo>
<ant:fileset id="hbm.fileset" dir="${maven.hibernate.generated.input.dir}" includes="${maven.hibernate.input.includes}"/>
<ant:pathconvert property="hbm.files" refid="hbm.fileset" pathsep=" "/>
<ant:java classname="net.sf.hibernate.tool.hbm2java.CodeGenerator"
failonerror="true">
<ant:classpath>
<ant:pathelement location="${plugin.getDependencyPath('hibernate-extensions:hibernate-tools')}"/>
<ant:pathelement location="${plugin.getDependencyPath('commons-collections:commons-collections')}"/>
<ant:pathelement location="${plugin.getDependencyPath('commons-logging:commons-logging')}"/>
<ant:pathelement location="${plugin.getDependencyPath('jdom:jdom')}"/>
<ant:path refid="maven.dependency.classpath"/>
</ant:classpath>
<ant:arg value="--output=${maven.hibernate.generated.output.dir}"/>
<ant:arg line="${hbm.files}"/>
</ant:java>
</goal>
3.
Add the following properties to the plugin.properties
maven.hibernate.generated.input.dir=${maven.src.dir}/conf/hibernate
maven.hibernate.generated.output.dir=${maven.src.dir}/java
4.
Ensure that hibernate-tools-2.1.2.jar is available at ibiblio.
It should now be possible to generate POJOs from hbm files. The POJOs will be placed in the src/java directory by default.
I am in the process of carrying out Step 4 myself and will hopefully do this soon.
Hope you find this worth consideration and hopefully it can make it into a future release.
Attachments
-
$i18n.getText("admin.common.words.hide")
- hibernate-tools-2.1.3.jar
- 08/Dec/04 4:55 PM
- 119 kB
- Paul Kearney
-
- META-INF/MANIFEST.MF 0.1 kB
- lgpl.txt 26 kB
- net/sf/.../MapGenerator$PEntity.class 0.7 kB
- net/sf/.../class2hbm/MapGenerator.class 13 kB
- net/sf/.../ReflectedArrayProperty.class 2 kB
- net/sf/.../class2hbm/ReflectedClass.class 8 kB
- net/sf/.../ReflectedCollectionProperty.class 2 kB
- net/sf/.../ReflectedComponent.class 4 kB
- net/sf/.../ReflectedListProperty.class 2 kB
- net/sf/.../ReflectedMapProperty.class 2 kB
- net/sf/.../class2hbm/ReflectedProperty.class 9 kB
- net/sf/.../ReflectedSetProperty.class 2 kB
- net/sf/hibernate/.../ddl2hbm/Gui$1.class 0.6 kB
- net/sf/hibernate/.../ddl2hbm/Gui$10.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$2.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$3.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$4.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$5.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$6.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$7.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$8.class 0.8 kB
- net/sf/hibernate/.../ddl2hbm/Gui$9.class 0.8 kB
- net/sf/hibernate/tool/ddl2hbm/Gui.class 23 kB
- net/sf/.../ddl2hbm/JDBCUtil$Column.class 1.0 kB
- net/sf/hibernate/.../ddl2hbm/JDBCUtil.class 8 kB
- net/sf/.../ddl2hbm/MapGenerator.class 15 kB
- net/sf/.../ddl2hbm/ParamsPanel$1.class 0.9 kB
- net/sf/.../ddl2hbm/ParamsPanel$2.class 0.8 kB
- net/sf/.../ddl2hbm/ParamsPanel$3.class 0.8 kB
- net/sf/.../ddl2hbm/ParamsPanel$4.class 0.8 kB
$i18n.getText("admin.common.words.show")- hibernate-tools-2.1.3.jar
- 08/Dec/04 4:55 PM
- 119 kB
- Paul Kearney
-
$i18n.getText("admin.common.words.hide")
- hibernate-tools-2.1.3-bundle.jar
- 13/Dec/04 4:54 PM
- 122 kB
- Paul Kearney
-
- META-INF/MANIFEST.MF 0.1 kB
- hibernate-tools-2.1.3.jar 119 kB
- LICENSE.txt 26 kB
- project.xml 0.6 kB
$i18n.getText("admin.common.words.show")- hibernate-tools-2.1.3-bundle.jar
- 13/Dec/04 4:54 PM
- 122 kB
- Paul Kearney
-
$i18n.getText("admin.common.words.hide")
- hibernate-tools-2.1.3-bundle.jar
- 11/Dec/04 6:34 PM
- 122 kB
- Paul Kearney
-
- META-INF/MANIFEST.MF 0.1 kB
- hibernate-tools-2.1.3.jar 119 kB
- LICENSE.txt 26 kB
- project.xml 0.6 kB
$i18n.getText("admin.common.words.show")- hibernate-tools-2.1.3-bundle.jar
- 11/Dec/04 6:34 PM
- 122 kB
- Paul Kearney
-
$i18n.getText("admin.common.words.hide")
- hibernate-tools-2.1.3-bundle.jar
- 08/Dec/04 4:57 PM
- 20 kB
- Paul Kearney
-
- META-INF/MANIFEST.MF 0.1 kB
- hibernate-tools-2.1.3.jar 10 kB
- project.xml 0.6 kB
- LICENSE.txt 26 kB
$i18n.getText("admin.common.words.show")- hibernate-tools-2.1.3-bundle.jar
- 08/Dec/04 4:57 PM
- 20 kB
- Paul Kearney
-
$i18n.getText("admin.common.words.hide")
- maven-plugins.zip
- 07/Dec/04 6:21 PM
- 62 kB
- Paul Kearney
-
- maven-plugins/bin/CVS/Entries 0.0 kB
- maven-plugins/bin/CVS/Repository 0.0 kB
- maven-plugins/bin/CVS/Root 0.0 kB
- maven-plugins/bin/hibernate.cfg.xml 0.9 kB
- maven-plugins/bin/hibernate.properties 0.2 kB
- maven-plugins/.../CodeGenerationBean.class 1 kB
- maven-plugins/.../CommonOperationsBean.class 2 kB
- maven-plugins/.../MappingsAggregatorBean.class 3 kB
- maven-plugins/bin/.../SchemaBeanBase.class 3 kB
- maven-plugins/bin/.../SchemaExportBean.class 1 kB
- maven-plugins/bin/.../SchemaUpdateBean.class 0.8 kB
- maven-plugins/bin/.../Component.class 0.7 kB
- maven-plugins/.../HibernateEntityResolver.class 2 kB
- maven-plugins/.../HibernateEntityResolverTest.class 2 kB
- maven-plugins/bin/.../hibernate/Item.class 0.7 kB
- maven-plugins/bin/.../hibernate/Item.hbm.xml 0.5 kB
- maven-plugins/.../AggregateMappingsTag.class 2 kB
- maven-plugins/.../CodeGenerationTag.class 2 kB
- maven-plugins/.../HibernateTagLibrary.class 0.9 kB
- maven-plugins/bin/.../SchemaExportTag.class 1 kB
- maven-plugins/bin/.../SchemaTagBase.class 3 kB
- maven-plugins/bin/.../SchemaUpdateTag.class 0.5 kB
- maven-plugins/bin/.../Message.hbm.xml 0.7 kB
- maven-plugins/bin/.../UserType.class 0.5 kB
- maven-plugins/CVS/Entries 0.0 kB
- maven-plugins/CVS/Entries.Static 0.0 kB
- maven-plugins/CVS/Repository 0.0 kB
- maven-plugins/CVS/Root 0.0 kB
- maven-plugins/CVS/Template 0.8 kB
- maven-plugins/hibernate/.cvsignore 0.1 kB
-
- patch.txt
- 07/Dec/04 6:20 PM
- 10 kB
- Paul Kearney
-
- patch-felipeal-1
- 12/Dec/04 5:58 PM
- 9 kB
- Felipe Leme
-
- patch-paulk-1.txt
- 12/Jan/05 3:24 PM
- 132 kB
- Paul Kearney
Activity
Paul, I think we corresponded offline about this bug. I wanted to make sure this hadn't fallen through the cracks. What is the current status on this.. I thought you sent me some files, but I can't find them. Can you attach them directly to the bug?
Eric,
yes we did correspond about this. I sent you some files that can be recreated by following the steps I detailed in my original comment. I have been a bit pressed for time recently but am going to look at implementing Felipes suggestions.
Once I have a working version of this I'll let you know.
Paul
Patch for source required in order to provide hbm-code-genration target. There is a futher zip'd file to be attached that contains the complete file structure with all my amendments included as the changes to the plugin.jelly, etc did not seem to be included in the patch (generated using Eclipse)
I have (I think) carried out all of Felipe's suggestions. I have updated the xdocs and provided a basic test case. I am reusing some properties that are used in other targets and maybe these should be seperated out.
Any further comments let me know and I'll see what I can do. I haven't as yet got round to uploading the hibernate-extenstions jar required for this plugin to work onto ibiblio and I have made assumptions about its group id.
Paul
Hi Paul,
I've tried to apply your patch, but that hibernate-extensions:hibernate-tools jar is not on ibiblio.
Could you please open a jira request for uploading it? Prefereably, versions 2.1.3 (which is the current version used by the plugin) and 2.1.6 (which is the most recent).
– Felipe
PS: here are the instructions on how to upload it:
Adding ibiblio upload bundle to this jira in order to make it readily available for inclusion in a further jira request to have it uploaded to the ibiblio server.
Apologies added the wrong jar. Adding the upload bundle jar this time.
Felipe,
I have placed a request for the upload of the hibernate-tools-2.1.3.jar to ibiblio as you suggested. If this goes ahead the project.xml for my patch will require to be updated to reflect the newer version of this jar (2.1.3 now, not 2.1.2).
Paul
Paul,
I did some minor modifications in the testcases and the patch is almost done. Still, I think it needs some more features before it can be applied:
- we need to tell the plugin which classes should or should not be generated. For instance, the current test case is regenerating the Item.java from Item.hbm.xml. In other words, we need a exclude/include pair of properties (something like maven.hibernate.generated.input.includes)
- also, the new goal should automaticaly add maven.hibernate.generated.output.dir to the src set expected by java:compile. I added 2 lines to teh tag, but I'm nto sure if that's the right way to do it (I mean, we should be doing that in the Java class, not in the Jelly script). Also, the test case is failing because now we have some duplicated Java files (see item above)
Anyway, I'm attaching the new patch (patch-felipeal-1).
Thanks,
Felipe
PS: to run the test-cases, simply type 'maven plugin:test' at the hibernate directory
properties
- we need to tell the plugin which classes should or should not be generated. For instance, the current test case is regenerating the Item.java from Item.hbm.xml. In other words, we need a exclude/include pair of properties (something like maven.hibernate.generated.input.includes)
- also, the new goal should automaticaly add maven.hibernate.generated.output.dir to the src set expected by java:compile. I added 2 lines to teh tag, but I'm nto sure if that's the right way to do it (I mean, we should be doing that in the Java class, not in the Jelly script). Also, the test case is failing because now we have some duplicated Java files (see item above)
Felipe,
The current plugin.jelly does support the exclusion of files from being generated. If you set maven.hibernate.input.excludes = org/apache/maven/hibernate/Item.hbm.xml then this should exclude the Item.java from being generated.
This just re-uses existing properties and I agree it may well be clearer to provide hbm generation specific properties rather than reusing existing ones. Both maven.hibernate.input.includes and maven.hibernate.input.excludes are reused in the plugin.jelly I submitted.
The second point regarding the addition of the generated source to the src set expected by the java:compile target I am not sure about.
For one this sounds like it may require overriding the class loader (something I have never attempted before), but it also strikes me as being beyond the scope of the plugin. It makes an assumption that everyone using the plugin will run java:compile after the code is generated. Would it not be more sensible to allow the person using the plugin to add the generated source directory to their java:compile set by configuring the maven.compile.src.set property of the java plugin. Personally, I set the maven.hibernate.generated.output.dir property to point to my projects java source directory (not that I am suggesting everyone should have to do this, but it does make sense to me).
Let me know if you agree or not.
Paul
I will be off-line for a couple of weeks, but will take a better look on the issue when I'm back (early January).
Felipe,
I have updated the plugin to have its own properties for excluding and including files for POJO generation.
Hope this solves some of the problems you raised with the previous version.
Hi Paul,
Sorry, but I've been too busy lately, so I hadn't have the time to look on your changes yet.
– Felipe
Paul,
I committed the changes, with one minor change: using codeGeneration instead of generated on the properties.
I also have a question for you: do you know how to setup hbm2java to add XDoclet tags (@hibernate) on the generated POJOs? I thought that would be possible, but didn't find anything on the CodeGenerator class...
– Felipe
Nevermind the XDoclet question, I figured it out myself - you need to add the XDoclet tags in a <meta> tag inside the .hbm.xml.
– Felipe
Excellent new Felipe. Do you know when this will make it into a release?
Paul
Hi Paul,
I'd like to have released 1.3 already, but haven't had the time yet ![]()
Hopefully I will do it by middle of next week.
– Felipe
Paul,
This feature seems very interesting and we would be glad to add a new goal for it in the plugin. But before we do so, I have some comments:
1.We are not using Jelly to write this plugin - all features are implemented in Java and we use Jelly only as a wrapper (take a look on the current code, it's pretty simple)
2.We need test cases for the new feature
3.Also, we would need that new feature documented (tipycally at xdocs/properties.xml and xdocs/goals.xml)
3.The best way to contribute is providing a patch (using cvs diff or a patch feature from your IDE - Eclipse, for instance, have a nice cvs support).
Could you try these 4 improvements and then attach the patch here on Jira?
– Felipe