-->
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:38 am 
Beginner
Beginner

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

je me demandais si toutes les fonctionnalites des fichiers .hbm.xml sont supportees par les annotations
En effet j'ai un code source assez complexe ecrit avec des fichiers de mapping .hbm.xml qui fonctionne
parfaitement sous hibernate 3.2.6 GA avec entity-manager 3.3.2 GA

les choses qui me semblent un peu "touchy" a convertir sont des classes sous classes en discriminant + table jointe dont
voici un example en hbm.xml
<?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>
J'ai essaye de passer hbm2java avec jdk5=true et ejb3=true mais il ne semble pas traiter ces cas car je ne trouve rien dans le code genere
qui ressemble a des @Discriminator ...

par avancer merci


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

Joined: Sat Jan 05, 2008 7:33 am
Posts: 26
En passant en pas a pas dans le code Hibernate, j'ai trouve ce qui ne fonctionnait pas

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.