User development,
A new message was posted in the thread "Replacing *.hbm.xml files with
@Annotations.":
http://community.jboss.org/message/524389#524389
Author : Jan Erik Robertsen
Profile :
http://community.jboss.org/people/janerikrob
Message:
--------------------------------------------------------------
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:
public class Attribute
{     private Long
id;     private String
name;     private String
value;     private
VocabularyElement
parent;     // This map
will result in its own table using the hbm.xml file listed
below.     // What
annotations can I use instead of the hbm.xml
file?     private
Map<String, String> extensionAttributes = new HashMap<String,
String>();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//
Constructors, getters,
setters&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// ...}
hbm.xml file for the Attribute class:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE
hibernate-mapping PUBLIC
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-//Hibernate/Hibernate
Mapping DTD
3.0//EN&nbsp;&nbsp;&nbsp;&nbsp;&n...
name="com.tracetracker.mds.adm.domain.Attribute">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<id
name="id"
access="field">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<generator
class="native"></generator>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</id>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<natural-id>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<property
name="name"
access="field"></property>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<many-to-one
name="parent"
class="com.tracetracker.mds.adm.domain.VocabularyElement"></many-to-one>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</natural-id>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<property
name="value"
type="text"></property>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<!--
This tag creates the extra table.
-->&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<map
name="extensionAttributes" table="Attribute_Attr"
order-by="attr_name asc" lazy="false"
access="field">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<key
column="id"></key>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<map-key
column="attr_name"
type="string"></map-key>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<element
column="attr_value"
type="string"></element>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</map>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</class></hibernate-mapping>
The resulting sql script:
create table Attribute
(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id int8 not
null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;name
varchar(255) not
null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;value
text,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;parent int8 not
null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;primary key
(id),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;unique (name,
parent));create table Attribute_Attr
(&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;id int8 not
null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr_name
varchar(255) not
null,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;attr_value
varchar(255),&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;primary
key (attr_name, id));alter table Attribute add constraint FK7839CA7C7FB02B5A foreign key
(parent) references VocabularyElement;alter table Attribute_Attr add constraint
FK4F4769F4A36A3D31 foreign key (id) references Attribute;
Any help is much apprecated.
--------------------------------------------------------------
To reply to this message visit the message page:
http://community.jboss.org/message/524389#524389