-->
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.  [ 7 posts ] 
Author Message
 Post subject: Mapping same classes to different table structure
PostPosted: Tue May 11, 2004 4:58 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Hi there,

Using Hiberante 2.1.3

I have the following mappings

agenciesLocations.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="gr.forthnet.openseas.models">   

<class name="Location" table="agencies_cities_counties" polymorphism="explicit">
        <id name="abbreviation"  column="county_en"  type="java.lang.String"  unsaved-value="null"  length="32">
            <generator class="hilo"/>
        </id>

        <property name="name" column="county_gr_en" not-null="true"/>
       
        <bag name="destinations" cascade="all" inverse="false" lazy="false">
           <key column="county_en" />
           <one-to-many class="Area" />
        </bag>
</class>

<class name="Area" table="agencies_cities_counties">
   <id name="abbreviation"  column="city_en"  type="java.lang.String"  unsaved-value="null"  length="32">
       <generator class="hilo"/>
    </id>

    <property name="name" column="city_gr_en" not-null="true"/>
       
    <many-to-one name="parent" class="Location" column="county_en" />
</class>
</hibernate-mapping>



locations.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="gr.forthnet.openseas.models">   

<class name="Location" table="destinations" polymorphism="explicit">
        <id name="abbreviation"  column="dabbr"  type="java.lang.String"  unsaved-value="null"  length="32">
            <generator class="hilo"/>
        </id>

        <property name="name" column="dname" not-null="true"/>
       
        <bag name="destinations" cascade="all" inverse="false" lazy="false">
           <key column="dabbr" />
           <one-to-many class="Area" />
        </bag>
</class>

<class name="Area" table="areas">
   <id name="abbreviation"  column="aabbr"  type="java.lang.String"  unsaved-value="null"  length="32">
       <generator class="hilo"/>
    </id>

    <property name="name" column="aname" not-null="true"/>
       
    <many-to-one name="parent" class="Location" column="dabbr" />
</class>
</hibernate-mapping>


Ofcourse I get a duplicate import error on this.

How can i make the above mappings and how do I distinguish them in HQL?

Thanks in advance

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 7:59 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can use two SessionFactories, but otherwise mapping one class twice in different ways is not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 8:38 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
So do I have to I remove any mappings in the configuration file and add them manually with the Configuration class?

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 8:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You can also use two different configuration files.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 8:54 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Yeah, but wouldnt that be obsolete? Having two configuration files with the same settings for the db and different mappings :/

PS. I just realised 'who you are' by clicking the www link on ur profile! Nice 2 meet u m8 :D

_________________
eu:life
http://www.eulife.gr


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 9:07 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It's your choice of course :) You can probably also use XML Entity includes in your config files to include the similar parts.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 11, 2004 9:37 am 
Regular
Regular

Joined: Tue May 04, 2004 6:15 am
Posts: 51
Hm... its going to be a little more tricky than I thought at first.

I can use one xml file for the common parts of the configuration as you mentioned, but since the DTD for hiberante.cfg.xml isn't specifying a separate tag for the database configuration section, when I import the common part I will get a validation error. Unless I'm missing smth.

If I instead decide to simply remove all the mapping declarations from the cfg file, then I have to add them in Java and that means hardcoding the filenames. Not elegant, but it works...

_________________
eu:life
http://www.eulife.gr


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