-->
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.  [ 4 posts ] 
Author Message
 Post subject: any type mappings
PostPosted: Tue Nov 18, 2003 12:06 pm 
Beginner
Beginner

Joined: Wed Sep 24, 2003 11:16 am
Posts: 20
Location: Turkey
Hi,
I'm trying to persist a polymorphic collection using Hibernate. The collection could include several classes which are all declared as subclasses of same parent using table per class hierarchy technique.
I suppose "any type mappings" are meant for this purpose. But I couldn't get a clear understanding from the docs, neither could find instructions elsewhere.
Any advice, help on "any type mappings" and "many-to-any" collections are greatly appreciated,
Thanks in advance.

Ahmet ISIK


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 18, 2003 5:19 pm 
Regular
Regular

Joined: Tue Sep 16, 2003 11:35 am
Posts: 93
Location: San Francisco, CA
If you need a collection of instances that are all subclasses of a persistent superclass, you can use one-to-many. Just use the superclass type.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 29, 2004 9:29 am 
Newbie

Joined: Thu Apr 29, 2004 9:19 am
Posts: 2
Here's some notes on how we have used the 'any' mapping:

We have a "note" table that is meant to hold a note for any item in any of the other tables in the schema. In the note table we have a column called table_name and table_id. table_name tells which other table this note is for, and table_id says which item in that table this note is for. We used an any mapping in hibernate for this like this (in the hibernate XML for my note class):

<any meta-type="com.incogen.hibernate.NameToDataHibernateMapper" name="item" id-type="long" cascade="none">
<column name="table_name" />
<column name="table_id" />
</any>

item is a member of my note class that is of type NoteRelated, which is extended by all classes that can have notes attached to them. NameToDataHibernateMapper is a child class of net.sf.hibernate.UserType which I learned more about from http://www.hibernate.org/122.html - it maps the table_name's to the proper java class (and vice-versa).

I am still trying to find the best way to reverse that any mapping so that the NoteRelated items can more easily find their notes, for now we are generating code to allow that.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 20, 2005 11:56 am 
Newbie

Joined: Thu Sep 01, 2005 8:43 am
Posts: 14
millz,

in case you are still watching this topic more than a year later :) I'll be ineterested if you made some progress w/ this. I'm having the same problem currently - speaking w/ your terms: I would need a Note collection in each NoteRelated subclass.

Help from anyone else is of course welcome as well :)

Thanks in advance,
landels


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