-->
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.  [ 5 posts ] 
Author Message
 Post subject: Do NOT fetch a subclass instance : how ?
PostPosted: Mon Sep 25, 2006 5:56 am 
Beginner
Beginner

Joined: Fri Sep 16, 2005 7:51 am
Posts: 25
Hi,

I'm stuck with an apparently simple problem.

I have two classes : A and B.

I'm using a single-table-per-class-hierarchy with discriminator column and default value (column is DTYPE and value is either 'A' or 'B').

When I try to fetch, with a named query - "from A" , all As, I get all Bs too (normal).

What I need is only A instances.

How can I do that with annotations (I didn't found the answer) ?

Thanks in advance for your help,

sne.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Sep 25, 2006 7:49 am 
Newbie

Joined: Tue Feb 08, 2005 6:16 am
Posts: 6
What I used was
Quote:
@Where(clause="discriminator_column_name='discriminator_value'")

as described by
http://forum.hibernate.org/viewtopic.php?t=961213


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 10:58 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you mean B is a subclass of A?
You can't and shouldn't try then
B is a A by definition
If you want A and not B, then your object design is wrong, you should redesign it maybe by using delegation

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 6:12 pm 
Beginner
Beginner

Joined: Fri Sep 16, 2005 7:51 am
Posts: 25
Ho, well, let me explain a little bit more what my problem is.
I have two classes "SimpleCustomer" and "SpecialCustomer", which extends "SimpleCustomer" and add some properties.
We may persists SimpleCustomers and SpecialCustomers, depending on the type of the customer.

But when I want only SimpleCustomer on the screen "Ol' Barney Store Simple Customer's list", I don't want to fetch from the DB SpecialCustomers too !

Why fetching datas I'm not interested in ? Do I have to fetch everything and sort later to remove from the result uninteresting objects ?
Or did I * really* missed something ? ;)


By the way : let's say that I saved a "SpecialCustomer" and, later on, am only interested by his "SimpleCustomer" properties for a use case (some 'condensed' view that show only all common properties for all Customers).

Must I :
- fetch my "SpecialCustomer"s, cast them into "SimpleCustomer"s and return them as is => useless datas will be fetched then ;
- use a very powerful feature of Hibernate I didn't found yet that can transtype my "SpecialCustomer" into a "SimpleCustomer" without complicated query ? (please note that I use a table-per-class-hierarchy with a discriminator column).

Thanks in advance for your aswers,

sne.[/list]


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 09, 2006 5:03 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I would
use a projection query which can be a select new SimpleObject(...)
or put my special data in a specific table and use delegation
or use the lightweight pattern( see the wiki community area)
or use bytecode enhancement and lazy property (@Basic(fetch=LAZY))

decreasing preferences

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.