-->
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: Modelling constrained Inheritance
PostPosted: Tue Feb 15, 2005 4:34 am 
Regular
Regular

Joined: Thu Feb 19, 2004 4:48 am
Posts: 62
I currently have a modelling problem , where I don't know how to model a simple composite-pattern. I have these classes:

A is abstract
B, C, D, E extend A

I model the inheritance using
@Inheritance(strategy=InheritanceType.JOINED)

B cannot be contained in other classes(isRoot)
B has a collection of sub-units, that can contain C and D
C can only contain classes of type E
E can contain no more other classes (isLeaf)

My first was to model this using a UnitType and a Jointable for AllowedSubunits:

UnitType
boolean isRoot
boolean isLeaf
Collection<UnitType> allowedSubtypes

AllowedSubunit:
parentUnit_id
subunit_id

I then add a many-to-one to the

----

This works quite ok, but has some drawbacks:
- I introduce a second typesystem (the A,B,C,D,E AND the UnitTypes) - there is nothing but the code that keeps this together.

- I have to hardcode the unitTypes in the constructors of the classes, to be able to set the correct unittype before I .save(newUnit)

----
Does anyone have a cleverer (and hopefully simpler) idea how to model this?!

cheers
stf


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.