1

I am using hbm2java (hibernate3-maven-plugin) in order to generate entities.

How do I switch the auto generated @EmbeddedId to @IdClass?

Thanks

Ozgur
  • 137
  • 2
  • 16

2 Answers2

0

The hibernate maven plugin doesn't do that automatically, you need to update your classes manually if you want to use @IdClass.

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • What about witout maven? Is is possible? – Ozgur Mar 18 '11 at 18:02
  • I don't know :(. I don't use the reverse engineering tools, because otherwise I can't change the entities into a domain model (for example I can't add methods). I suggest you to create the files the first time and then customize them to do what you want. – Augusto Mar 18 '11 at 18:06
  • you are right. I have just checked out source code of the hibernate tools. This feature does not exist in template files. I have a terrible disappointment now. – Ozgur Mar 18 '11 at 22:59
  • Ahh! And be careful if you put and enums mapped as string in your composite IDs using @IdClass, there's a dodgy, sporadic bug in which hibernate transforms uses the ordinal instead of the string :(. This doesn't happen if you map it with @EmbeddedId – Augusto Mar 18 '11 at 23:36
0

I have not tried to following. But from what I have been working with Hibernate reverseengineering tool I think it should be possible by using a reveng.xml file. In your pom file.

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>hibernate3-maven-plugin</artifactId>
    <version>2.2</version>
    <configuration>
    <components>
        <component>
            <name>hbm2java</name>
        </component>
    </components>
    <componentProperties>
       <revengfile>/src/main/resources/reveng/model.reveng.xml</revengfile>
    </componentProperties>
    </configuration>
    <executions>
  <execution>
  <phase>compile</phase>
  <goals>
    <goal>hbm2java</goal>
  </goals>
  </execution>
</executions>

And in the reveng.xml specify the type mapping to the IdClass (see Hibernate tools documentation http://docs.jboss.org/tools/3.1.0.GA/en/hibernatetools/html_single/index.html#type_map or http://docs.jboss.org/tools/3.1.0.GA/en/hibernatetools/html_single/index.html#d0e5869).

As mentioned, I have not tried it.

For various other reason I gave up on using reverse engineering. One problem is that hibernate tools is not compliant with Hibernate 3.5 and above. Furthermore the Maven plugin is third party and uses an older versions of Hibernate tools, than the one general available. So I also came into the situation where I had to call ant from Maven to do the reverse engineering.

  • Yes you are right. It is possible to use a reveng file. However I could not understand type_map section. As far as I understood it can be used to map jdbc_type's to java types. My second question will be regarding ant configuration. If you dont mind, would you share it too? – Ozgur Mar 21 '11 at 20:13
  • The hibernate doc links are no longer available. Does anyone have updated links? – Jason Jan 19 '14 at 18:59