-->
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: Problem with class discrimination and HibernateAnnotations
PostPosted: Mon Nov 06, 2006 7:29 am 
Newbie

Joined: Mon Nov 06, 2006 6:45 am
Posts: 2
Hi Dev's

I am doing my first steps with HibernateAnnotations (cool!).
I have an abstract class wherefrom two other classes are extending.
Both these classes I want to persist in one table, doing the
discrimination by 'defining a formula' (a field existing only
in one of the subclasses, lets say UserTypeB):

In short something like:

@MappedSuperclass
@Inheritance(strategy=InheritanceType.SINGLE_TABLE)
@DiscriminatorFormula("case when type is null then 'A' else 'B' end")
public abstract class AbstractUser implements Serializable, Comparable {
...
}

@Entity
@Table (name="`GEOENTRY`")
@DiscriminatorValue("A")
public class UserTypeA extends AbstractUser {
...
}

@Entity
@Table (name="`GEOENTRY`")
@DiscriminatorValue("B")
public class UserTypeB extends AbstractUser {
...
}


So far everyting looks nice. I can persist objects into the database.
However, if I search for all existing objects stored, I get a collection twice
the size
of existing rows. Concretely, I get for every row an instantiated
object of UserTypeA and UserTypeB, each.

I am very sure that I am simply doing something wrong with using the Annotations.

Can someone point out what I am doing wrong?
Is there some other recommendation to implement this?
Some other source of good examples (besides the Annotation documentation)

Thanks for any beginner's help!


Environment:
- Hibernate 3.2.0.ga
- HibernateAnnotations 3.2.0.ga
- Database: Postgres 8.1
- Using Session and Transaction handling provided by HibernateTemplate of the Springframework


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 2:48 pm 
Newbie

Joined: Mon Nov 06, 2006 6:45 am
Posts: 2
Stupid error:
Don't specify the table (@Table (name="`GEOENTRY`") ) multiple times!
Only once, in the abstract class, and everything works fine.


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.