-->
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: What is the Best Way to Do This?
PostPosted: Mon Oct 06, 2008 3:49 pm 
Newbie

Joined: Mon Oct 06, 2008 3:34 pm
Posts: 2
Basically, my scenario is that I have a class which has around 25-50 subclasses which I would like to add persistence to. Rather than have a schema defined for each subclass (each class differs only by one or two fields), is it possible to accomplish this using something along the lines of:

1. Have a single table which I map the base class on to.

2. Have an additional column which is a binary blob, xml, or something equivalent.

3. Use some sort of custom serializer to serialize the additional fields of all the subclasses to the additional column from bullet 2. There can also be an additional column which is used to distinguish which subclass it is.

This would save me from having to tediously define the schema for all of the subclasses, especially since all of the subclasses are most likely going to change schema before the project is completed.

Is this even a viable option? Is it a horrible idea?

Thanks,
Gordon

_________________
http://hempton.com


Top
 Profile  
 
 Post subject: Table per class hierarchy
PostPosted: Tue Oct 07, 2008 3:06 am 
Newbie

Joined: Fri Nov 30, 2007 7:23 am
Posts: 3
Hi Gordon,
If I understood correctly, what you need is a mapping strategy called 'Table per class hierarchy' . You could read more about it here :
http://www.hibernate.org/hib_docs/refer ... leperclass

Hope it helps,
kama


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 3:29 am 
Newbie

Joined: Fri Aug 29, 2008 9:07 am
Posts: 16
Location: edinburgh/zielona gora
Or try use relation ManyToAny: http://www.hibernate.org/hib_docs/annot ... ml_single/

Let us know if that was what you were looking for ;)

radek


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 07, 2008 4:52 am 
Newbie

Joined: Mon Oct 06, 2008 3:34 pm
Posts: 2
Thanks for your responses, however I think that neither of the solutions are exactly what I am looking for, although I will probably wind up just going with the table-per-class-heirarchy mapping.

I actually do not understand entirely what the @ManyToAny or @Any annotations do, as there is not much documentation/examples for them.

I guess what I was asking for was a way to free myself from the requirement of having all my data be structured in the persistence layer (probably not a good idea with rdbms/hibernate). It would be nice if in certain cases I could just store some "bits" inside of a column which could be deserialized into the java bean when they are loaded from the persistence layer. This would of course come at the price of not being able to access the fields from hql/criteria etc, since the data would be schema-less and would basically be unstructured data inside of a binary column.

_________________
http://hempton.com


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.