-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: .hbm.xml vs annotations
PostPosted: Mon Jun 22, 2009 9:42 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
Hello

I was wondering if all functional aspects provided by .hbm.xml mapping files were also supported by annotations
I've written a quite complex source code with .hbm.xml mapping files which works perfectly well under
hibernate 3.2.6 GA and entity-manager 3.3.2 GA and wanted to move to annotations

things which seem to me a little bit awkward to guess from docs are sub classes with mixed discriminant and joined subtables
like in the following example

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping default-lazy="false" default-cascade="all" package="test.messages">
<class name="InfoGroup" table="InfoGroups">

<id name="dbId" column="db_id" type="long">
<generator class="native"/>
</id>
<discriminator column="tag" type="string"/>
<timestamp name="lastModified" column="last_modified" source="db"/>
<property name="created" type="timestamp" insert="false" update="false" generated="insert"/>

<property name="digest" column="digest" type="string"/>

<properties name="key" unique="true">
<property name="active" column="is_active" type="boolean" not-null="true" index="ix_infogroups_ac"/>
<property name="journalId" column="distro_id" type="long" index="ix_infogroups"/>
<property name="name" column="name" type="string" index="ix_infogroups"/>
<property name="version" column="version" type="string"/>
<property name="release" column="infogroup_release" type="string"/>
</properties>
<property name="description" column="description" type="text"/>
<property name="category" column="category" type="string"/>

<subclass name="MovieInfo" discriminator-value="MovieInfo"/>
<subclass name="MusicInfo" discriminator-value="MusicInfo"/>
<subclass name="SpecialInfo" discriminator-value="SpecialInfo">
<join table="Specials">
<key column="db_id" foreign-key="fk_special_infogroup"/>
<property name="Specialty" column="is_special" type="boolean"/>
</join>
</subclass>
<subclass name="MyInfo" discriminator-value="MyInfo">
<set lazy="true" name="journals" table="lt_myinfo_journals">
<key column="myinfos_journals_id" foreign-key="fk_myinfo_journals_id"/>
<many-to-many class="Journal" column="journal_id" foreign-key="fk_myinfo_journals"/>
</set>
<join table="MyInfos">
<key column="db_id" foreign-key="fk_myinfo_infogroup"/>
<property name="revision" column="revision" type="integer"/>
</join>
</subclass>
</class>
</hibernate-mapping>

I tried hbm2java with jdk5=true & ejb3=true but it does not seem to be able to handle this properly as I could not find
anything in the generated code which looks like @Discriminator ...

thanks in advance


Top
 Profile  
 
 Post subject: Re: .hbm.xml vs annotations
PostPosted: Tue Jun 23, 2009 8:11 am 
Beginner
Beginner

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
Ok going step by step in hibernate code I found out what was wrong

Main class:

@Entity
@DiscriminatorColumn(name = "tag", discriminatorType = DiscriminatorType.STRING)
@Inheritance(strategy = InheritanceType.JOINED)
@Table(name = "InfoGroups", uniqueConstraints = @UniqueConstraint(columnNames = {"is_active", "journal_id", "name", "version", "infogroup_release"}))
@XmlRootElement(name = "PkgGroup")
public class InfoGroup implements Serializable {

...
}

for discriminant only inheritence

@Entity
@DiscriminatorValue("MovieInfo")
public class MovieInfo extends InfoGroup implements Serializable {
...
}

and for joined and discriminant inheritence

@Entity
@DiscriminatorValue("SpecialInfo")
@PrimaryKeyJoinColumn(name="db_id")
@Table(name = "Specials")
public class SpecialInfo extends InfoGroup implements Serializable {
...
}

do not try to specify the table for discriminant only inherience else you'll run into hibernate exception at runtime


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.