-->
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.  [ 1 post ] 
Author Message
 Post subject: Inheritance mapping (hbm => annotations)
PostPosted: Mon Jun 28, 2010 6:55 am 
Newbie

Joined: Sun Dec 28, 2008 2:58 pm
Posts: 5
Hi, I have hbm file, which I need to rewrite to annotations. It consists of two classes Article and ArticleDetails (which extends article), the first is used in the app for navigation generation (it contains only menuHeading property), class ArticleDetails has more information (attachments, comments, article itself etc.). With hbm mapping I had them mapped in one table, without any discripminators, I have explicitly told hibernate wheather I want the first one or the second class. But I cannot figure out how to do this with annotations, because I always get two tables...

Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
  <class name="cz.flexibla.common.bo.Article" table="article">
    <id name="id" type="java.lang.Long">
      <column name="id"/>
      <generator class="sequence"/>
    </id>
    <property name="menuHeading" not-null="true" type="java.lang.String"/>
    <property name="identifier" not-null="true" type="java.lang.String" unique="true"/>
    <set cascade="all" inverse="true" lazy="true" name="articleCategories" order-by="priority">
      <key column="article"/>
      <one-to-many class="cz.flexibla.common.bo.ArticleCategory"/>
    </set>
  </class>
  <class name="cz.flexibla.common.bo.ArticleDetails" polymorphism="explicit" table="article">
    <id name="id" type="java.lang.Long">
      <column name="id"/>
      <generator class="sequence"/>
    </id>
    <property name="menuHeading" not-null="true" type="java.lang.String"/>
    <property name="identifier" not-null="true" type="java.lang.String" unique="true"/>
    <set cascade="all" inverse="true" lazy="true" name="articleCategories" order-by="priority">
      <key column="article"/>
      <one-to-many class="cz.flexibla.common.bo.ArticleCategory"/>
    </set>
    <!-- To, co maji detaily navic -->
    <many-to-one name="template" />
    <property name="heading" not-null="true" type="java.lang.String"/>
    <property column="article" lazy="true" name="text" not-null="true" type="text"/>
    <property column="articleUntransformed" lazy="true" name="articleUntransformed" not-null="true" type="text"/>
    <set cascade="all-delete-orphan" inverse="true" lazy="true" name="comments" order-by="stamp ASC">
      <key column="article" on-delete="cascade"/>
      <one-to-many class="cz.flexibla.common.bo.Comment"/>
    </set>
    <set cascade="all-delete-orphan" inverse="true" lazy="true" name="attachments">
      <key column="article" on-delete="cascade"/>
      <one-to-many class="cz.flexibla.common.bo.Attachment"/>
    </set>
  </class>
</hibernate-mapping>


Code:
@Indexed
@SuppressWarnings("serial")
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
@Table(name="Article")
public class Article extends AbstractBusinessObject {
    @Column(unique=true, nullable=false)
    private String identifier;
    @Column(nullable=false)
    private String menuHeading;
    @OneToMany(cascade=CascadeType.ALL, mappedBy="article")
    private Set<ArticleCategory> articleCategories;
    @OneToMany(cascade=CascadeType.ALL, mappedBy="article")
    private Set<Comment> comments;

//getters and setters here
}



Code:

@Indexed
@AnalyzerDef(name = "customAnalyzer",
tokenizer =
@TokenizerDef(factory =
HTMLStripStandardTokenizerFactory.class),
filters = {
    @TokenFilterDef(factory = DiacriticsFilterFactory.class),
    @TokenFilterDef(factory = LowerCaseFilterFactory.class)
})
@Entity
public class ArticleDetails extends Article {

    private static final long serialVersionUID = 1L;
    @Field(index = Index.TOKENIZED, boost =
    @Boost(5f))
    @Analyzer(definition = "customAnalyzer")
    @Column(nullable = false)
    private String heading;
    @Field(index = Index.TOKENIZED)
    @Analyzer(definition = "customAnalyzer")
    @Column(nullable = false)
    @Type(type = "text")
    private String text;
    @Column
    @Type(type = "text")
    private String articleUntransformed;
    @OneToMany(cascade = CascadeType.ALL, mappedBy="article")
    private Set<Attachment> attachments;
    @ManyToOne
    private Template template;

//getters and setters here
}


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

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.