-->
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: any and one-to-many mapping
PostPosted: Mon Sep 04, 2006 3:03 pm 
Newbie

Joined: Thu Nov 04, 2004 7:53 am
Posts: 3
Hibernate version:

2.1.6

Name and version of the database you are using:

Oracle 10g

Hi,

I have the following hierarchy I'm trying to represent in hibernate.

TypeA implements IType
TypeB implements IType
TypeC implements IType

IType has a Map of Entities, so the entities table has a getIType method
which uses <any> mapping and the entities table has type and itype_key
columns.

TypeA, TypeB and TypeC declare the Map with a <one-to-many> mapping to
the class Entity.

Things work great when I want to save the information to the database,
I can do the following:

TypeA a = new TypeA();
a.setEntities(mapOfEntitiesForA);

TypeB b = new TypeB();
b.setEntities(mapOfEntitiesForB);

TypeC c = new TypeC();
c.setEntities(mapOfEntitiesForC);

session.save(a);
session.save(b);
session.save(c);

And in the entities table, the type column will be filled with the
class type of A, B or C as appropriate.

But when I read in the data, such as the following:

TypeA a1 = session.get(TypeA.class, a.getKey())

a1.getEntities() contains all the entities, not just the ones
where the type field is TypeA. The SQL select statement issued
by hibernate doesn't search by type, just by TypeA.key

Any ideas where I'm going wrong?

Mark


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.