-->
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: Mapping POJO to m ore than 1 table
PostPosted: Tue May 26, 2015 6:39 am 
Newbie

Joined: Tue May 26, 2015 6:21 am
Posts: 1
Hello, I'm tryin to map a single class to 2 different tables, but i'm having some problems in making it work.
I've tried the approach listed here

http://www.coderanch.com/t/492558/ORM/databases/Mapping-POJO-table-Hibernate-XML

i created 2 xml that referes to the same class, the xml code is pretty much the same, only difference is that
one field of my pojos is loaded from different tables with a join, while the remaining fields are all being loaded for the main table (I have an "Item" pojo, with some attributes loaded from the Item table, and an int quantity, which is loaded from the Order table or the Storage table).

<class name="model.MyClass" table="tab1" entity-name="entity1">
and
<class name="model.MyClass" table="tab2" entity-name="entity2">

and declared them in the hibernate.cfg.xml like this

<mapping resource="model/entity1.hbm.xml" />

but i keep getting errors.

To be more specific, I started creating the mapping for tab1, and everything works untill i add the entity-name tag, even with only 1 xml mapping..

Thanks for any input


Top
 Profile  
 
 Post subject: Re: Mapping POJO to m ore than 1 table
PostPosted: Wed Jun 17, 2015 3:52 am 
Newbie

Joined: Mon Apr 30, 2012 2:19 am
Posts: 6
Check the sample : https://bitbucket.org/ecornely/secondarytable/src

This is a maven project where I configured a persistence.xml and a orm.xml (the standard JPA files replacing hbm)

You will see in orm.xml a secondary table saying that the biography attribute is stored in a second table.

I suppose the same kind of stuff can be done with hibernate configurations though I prefer the standard when it's possible :-P


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.