This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
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

wood burning stoves
subject: Replacing *.hbm.xml files with @Annotations.
Similar Threads
Hibernate replacing my tables
what changes should i made in save method in one-to-many relationships
SecondaryTable Mapping
autogenerating db-schema cascade=CascadeType.REMOVE but no ON DELETE CASCADE
Cascading non foreign key to Child Table