-->
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: mapping multiple classes to one table using hbm.xml
PostPosted: Thu Jan 05, 2012 3:30 am 
Newbie

Joined: Thu Jan 05, 2012 3:25 am
Posts: 1
I am fairly new to Hibernate and need some help with hibernate-mapping.

I have 4 different classes which I want to map into one table, of which the primary key consists of attributes from 2 different classes. At the same time, I want to map only selected attributes from each class into a local database. I wish to avoid JPA annotations and define the mapping style in a hbm.xml file instead. How do I do that?

Take the following example:
Code:
public class Tenant implements Serializable {
        private final static long serialVersionUID = 1L;
        protected List<Rack> rack;
        protected String type;
        //getters setters
    }

    public class Rack implements Serializable {
        private final static long serialVersionUID = 1L;       
        protected List<Circuit> circuit;
        protected String rackLabel;
        protected Boolean excludes;
        //getters setters
    }

    public class Circuit implements Serializable {
        private final static long serialVersionUID = 1L;
        protected List<CircuitReadings> circuitReadings;
        protected String circuitNo;
        protected Boolean excludes;
        //getters setters
    }

    public class CircuitReadings
        implements Serializable {
        private final static long serialVersionUID = 1L;
        protected String date;
        protected String kva;
        protected String current;
        protected String kwh;
        //getters setters
    }


And the eventual table should consist of the following:

Code:
type | rackLabel | circuitNo | date | kva | current | energy

"circuitNo" and "date" above should form the composite primary keys.

Can someone show me an example of how I should map this? Thanks!


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.