-->
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.  [ 2 posts ] 
Author Message
 Post subject: Particular inheritance mapping
PostPosted: Wed Mar 31, 2004 4:58 am 
Newbie

Joined: Wed Mar 31, 2004 4:44 am
Posts: 1
Let me explain the problem I have:

Code:
public class Z {
protected Z();  // protected constructor.
public boolean active;
}

public class A extends Z {
public long id;
public String name;
}

public class B extends Z {
public long id;
public String color;
}


Here is the hibernate mapping I try to do:

class Z do not need a real table, constructor is protected, so no self instance of Z can exist. Those class simply provide common features to subclass.

In fact, I need to have only two database tables :

Code:
TABLE_A
- id
- name
- active   <= from Z

TABLE_B
- id
- color
- active  <= from Z


That all, But I cannot find how to do those map in hibernate.
It seems that is not possible to do the trick like this.

With table-per-hierarchy (<subclass>) strategie mapping we have one big table with discriminator. But this way introduce problem for not null field constraints on subclass.

With table-per-subclass (<joined-subclass>) strategie mapping we will have three databses tables with one-to-one relation between A,Z and B,Z.
(that not what I want for performance reasons)

With table-per-concrete-class (<any>) strategie mapping, it seems that we have to include all Z persistant fields inside A and B. So we must map the 'active' field in all subclass. (I want to avoid to repeat the 'active' field in each subclass)

Is there a way to do the trick without explicitly map the 'acitve' field inside each subclass ? The goal is to provide the 'active' persistant field inside Z class and never have to make map each time we create a new subclass.

Thanks in advance for all your comments.

_________________
----
OD.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Mar 31, 2004 8:56 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
1. use XML entity to avoid redundancy
2. use xdoclet to generate your mapping files. It'll do the duplication for you

_________________
Emmanuel


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