-->
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.  [ 5 posts ] 
Author Message
 Post subject: Can I map one object into two tables?
PostPosted: Sat Aug 21, 2004 12:35 am 
Newbie

Joined: Sat Aug 21, 2004 12:22 am
Posts: 3
I have a POJO class that will map to two tables, I have created one mapping document. Let's say user.hbm.xml. The database has user and secretinfo table. The secretinfo will store some secret information. The user object will map the user into user table only. Where I can the mapping to map the user's secret info to table secretinfo?

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

<hibernate-mapping>
<class name="com.test.user" table="user">
<id name="loginname" column="LOGINNAME" type="java.lang.String">
<generator class="assigned"/>
</id>
<property name="password" column="PASSWORD" type="java.lang.String" />
<property name="phone" column="PHONE" type="java.lang.String" />
<property name="fax" column="FAX" type="java.lang.String" />
</class>
</hibernate-mapping>

Hibernate version:
2.1.6

Name and version of the database you are using:
MySQL 4.0


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 21, 2004 12:54 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
you can do it in HIbernate3, however, we dont really think its a good idea from an object modelling pov. better to create a SecretInfo class.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 8:38 pm 
Newbie

Joined: Thu Aug 05, 2004 6:01 pm
Posts: 18
Location: New Zealand
I was looking for this solution, and as we are not using Hibernate 3 then I guess it is not available to us.

I was curious as to the response "we dont really think its a good idea from an object modelling pov".

We are using Hibernate over a legacy database and have two tables that really should map to one object.

I would have thought that from an object modelling pov the application domain would define the objects required and how they are persisted in my database is an entirely separate decision? The mapping is what isolates this.

Regards
Shane


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 8:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
"Good" object models are *very* fine grained, IMO. So we usually say that if your object model is not *at least* as finegrained as your relational model, there is something wrong. :-)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 02, 2004 9:34 pm 
Newbie

Joined: Thu Aug 05, 2004 6:01 pm
Posts: 18
Location: New Zealand
Hence the reply to the OP. That makes sense to me.

In fact I have just now flicked open a chapter in Eric Evan's book Domain-Driven Design that recommends keeping the object model and data model as close as possible no matter what the power of the mapping tool allows.

Then he mentions that often data in legacy systems was never intended as a store for objects. So this being a different issue then the decision to make is whether I wish to make the object model conform to the existing data model or to make my object model completely distinctive.

Thanks
Shane


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