-->
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.  [ 9 posts ] 
Author Message
 Post subject: Inheritance mapping problem to existing db
PostPosted: Thu Mar 18, 2004 10:58 am 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
In existing db I have two tables, BASE_TBL and BASE_EXPERT.
A would like to have BaseExpert class that inherits from Base class.
Both tables have baseId field, that si de facto association one-to-one.

My question is: It is possible with hibernate to do such mapping next mapping?

BASE_TBL will be mapped to Base class and BASE_TBL+BASE_EXPERT will be mapped to BaseExpert class.

So when I will create new BaseExpert and save it, two inserts will go to db, insert to BASE_TBL and insert to BASE_EXPERT.

Thanks for any help


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 11:19 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
http://www.hibernate.org/hib_docs/refer ... ritance-s1

you seem to be in table-per-subclass mapping case.
just follow the steps of the docs, it works great


Top
 Profile  
 
 Post subject: Solution with problem - force table for subclass with xdocle
PostPosted: Thu Mar 18, 2004 12:49 pm 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
Here are example of solution. But there is one problem. I would like to define table (table name) for joined subclass. How can I do it using xdoclet hibernate tags?

In base.hbm.xml should be added line with bold. This line is missing after hbm generation of this example.

<joined-subclass
name="com.pxpfs.excom2.finance.domainmodel.BaseExpert"
table="A_BASE_EXPERT_TBL"
dynamic-update="false"
dynamic-insert="false"
>


BASE class

Code:
/**
* @hibernate.class table="A_BASE_TBL"
*/
public class Base implements java.io.Serializable {
    public Long baseId;
    public String name;

    public void setBaseId(Long baseId) {
        this.baseId = baseId;
    }

    /**
     * @hibernate.id generator-class="native"
     */
    public Long getBaseId() {
        return baseId;
    }

    public void setName(String name) {
        this.name = name;
    }

    /**
     * @hibernate.property length="60"
     */
    public String getName() {
        return name;
    }

    public Base() {
        super();
    }
}


ANCESTOR CLASS - JOINED SUBCLASS
Code:
/**
* not good !!!! @ hibernate.class table="A_BASE_EXPERT_TBL"
* @hibernate.joined-subclass table="A_BASE_EXPERT_TBL"
* @hibernate.joined-subclass-key column="baseId"
*/
public class BaseExpert extends Base implements java.io.Serializable {
    public String description;

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @hibernate.property length="60"
     */
    public String getDescription() {
        return description;
    }

    public BaseExpert() {
        super();
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 12:54 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
humm i have an example at home
what about writing only thiese two lines?


* @hibernate.joined-subclass table="A_BASE_EXPERT_TBL"
* @hibernate.joined-subclass-key column="baseId"


Top
 Profile  
 
 Post subject: it does not work - @hibernate.joined-subclass table ...
PostPosted: Thu Mar 18, 2004 1:08 pm 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
xdoclet tag "@hibernate.joined-subclass"
have not attribute -> table="A_BASE_EXPERT_TBL"

Look at my example.

If you have solved it at home through xdoclet, please, send me this solutions.

Maybe some merging is solution? But I don't know how to do that.


Top
 Profile  
 
 Post subject: Correction...
PostPosted: Thu Mar 18, 2004 1:42 pm 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
Sorry, it seems that
Code:
@hibernate.joined-subclass table="A_BASE_EXPERT_TBL"
is working.
I don't know were was a problem, from some time it started to work.
Maybe I need some rest :-) Thaks for help.

Complete example of ANCESTOR CLASS - JOINED SUBCLASS
Code:
/**
* @hibernate.joined-subclass table="A_BASE_EXPERT_TBL"
* @hibernate.joined-subclass-key column="baseId"
*/
public class BaseExpert extends Base implements java.io.Serializable {
    public String description;

    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * @hibernate.property length="60"
     */
    public String getDescription() {
        return description;
    }

    public BaseExpert() {
        super();
    }
}


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 18, 2004 3:32 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
you had to know that if Base class has composite id, xdoclet is unable to generate subclasses well :(
two @hibernate.joined-subclass-key tags is not allowed

i'm trying to code a patch, but i'm have no time.... if you want to take a look...


Top
 Profile  
 
 Post subject: reply
PostPosted: Fri Mar 19, 2004 1:16 am 
Regular
Regular

Joined: Fri Nov 21, 2003 10:23 am
Posts: 81
I have removed all composite ids, because not at nice implementation in hibernate, expecially in xdoclet. There is many problems.

Tnx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 3:56 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
because not at nice implementation in hibernate


i'm using composite ids, works perfectly, the only problem is about xdoclet and subclass (without subclass, mapping files are well generated).


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