-->
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.  [ 3 posts ] 
Author Message
 Post subject: object heirarchy & different tables using entity-name?
PostPosted: Fri Jun 09, 2006 7:21 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 4:11 pm
Posts: 24
Right now I have a class heirarchy for example:

Code:
abstract class A {}
class B extends A {} // maps to table TB
class C extends A {} // maps to table TC


and I will have code to save the objects:

Code:
A b = new B();
A c = new C();
session.save(b); // inserted into table TB
session.save(c); // inserted into table TC


what I would like is the ability to have parallel set of tables depending on the entity name attribute provided to the save method, for example:

Code:
abstract class A {} // mapped to entity-names E1,E2 in different <class>
class B extends A {} // maps to table TB1 and TB2 respectively
class C extends A {} // maps to table TC1 and TC2 respectively


Code:
A b1 = new B();
A c1 = new C();
A b2 = new B();
A c2 = new C();
session.save("E1",b1); // inserted into table TB1
session.save("E1",c1); // inserted into table TC1
session.save("E2",b2); // inserted into table TB2
session.save("E2",c2); // inserted into table TC2


I would like the entity-name attribute inherited so I don't have to know what subclass is being saved. I did notice someone have a problem with inheriting entity-name
but I do not mind hard-coding the entity-name for each subclass to be the same.

I've tried setting this up using two xml mapping files and have the entity-name attribute be inherited and just hardcoded to be the same for each heirarchy, but run into errors while parsing the configuration files. Is this even possible??

thanks


Top
 Profile  
 
 Post subject: Re: object heirarchy & different tables using entity-nam
PostPosted: Sat Jun 10, 2006 5:00 am 
Beginner
Beginner

Joined: Tue Oct 18, 2005 3:57 pm
Posts: 48
Location: Los Angeles, CA
genekhart wrote:
I would like the entity-name attribute inherited so I don't have to know what subclass is being saved....
but I do not mind hard-coding the entity-name for each subclass to be the same.

If you're willing to hard-code entity names, why not make the entity names part of the class names? For example:

Code:
abstract class A_E1, A_E2
class B_E1 extends A_E1, B_E2 extends A_E2
class C_E1 extends .....

This way, you can simply use a NamingStrategy to decide which table to write to, i.e.:

Code:
public String classToTableName(String className) {
    if ("B_E1".equals(className)) {
        return "TB1";
    } else if ("B_E2".equals(className)) {
        return "TB2";
    } else if (...) {
        ....
    }


Top
 Profile  
 
 Post subject: not exactly
PostPosted: Mon Jun 12, 2006 10:28 pm 
Beginner
Beginner

Joined: Thu Jun 23, 2005 4:11 pm
Posts: 24
Thank you for the suggestion but it appears your method would require having different classes for each table. Using the entity-name approach this would not be required, and would be preferred so I don't have to maintain redundant class definitions.

To me it just seems like a bug, and entity-name cannot be inherited. It probably stems from (a guess) the table name is associated using only the entity-name(default class name), and not the combination of the entity-name and class name.

I might instead use some sort of discrimanator column and use database partitioning to split up the data into separate tables at that level, but this would not be as portable as I'd like it to be.


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