File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Object Relational Mapping and the fly likes Replacing *.hbm.xml files with @Annotations. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Replacing *.hbm.xml files with @Annotations." Watch "Replacing *.hbm.xml files with @Annotations." New topic

Replacing *.hbm.xml files with @Annotations.

Jan Erik Robertsen

Joined: Feb 05, 2010
Posts: 1
I have three java classes that are persisted using hibernate. I want to switch from using *.hbm.xml files to annotations on these classes. However the db has additional tables that are created by tags in hbm.xml. Is there a way to create these extra tables using annotations without having to create additional java classes.

One of the java classes that result in two tables in db:

hbm.xml file for the Attribute class:

The resulting sql script:

Any help is much apprecated.
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

I'm wondering if the @SecondaryTable annotation might do the trick? Here's an example:

Mapping One Class to Two Tables with Hibernate and JPA

I agree. Here's the link:
subject: Replacing *.hbm.xml files with @Annotations.
It's not a secret anymore!