-->
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: Mapping question
PostPosted: Sun Oct 23, 2005 8:49 pm 
Newbie

Joined: Sun Oct 23, 2005 8:33 pm
Posts: 4
Hi, everyone. I am new to hibernate, so my question may be stupid.
Anyway, I am on a project which using hibernate, and I need to do some kinda column mapping.

Here is an example, let's say I have 2 tables T1, and T2, each of which has 3 columns, all named x1, x2, x3. Then I have a java class JClass with 2 private variables: id and value. I want to map JClass to both T1 and T2.

When I ask hibernate to return a row of T1, a collection of JClass instantces will be returned. Each instance's id is column name and value is the value of that column for a specific row.

Can hibernate do that? If it can, would someone give me the mapping xml file based on above example?

Thank you very much and have a nice day.














Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:

Name and version of the database you are using:

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: IMO
PostPosted: Sun Oct 23, 2005 10:03 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Well, firstly we do not ask H to return row from TableX as object, we as H to get object of a given type with the given identity. See the difference? When dealing with H it helps to think in terms of objects rather than tables, rows and columns.

iBatis ( http://ibatis.apache.org/ ) is the tool that supports your way of thinking: bring me row from table Z as object JClass, or bring me row from table Y as object of JClass.

That was a long way to say no, H does not allow the thing you have asked for.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:07 am 
Newbie

Joined: Sun Oct 23, 2005 8:33 pm
Posts: 4
Maybe this is called "map properties of one class to several tables"
Can the value variable of JClass be mapped to all 6 columns?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 10:30 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
maxSB wrote:
Maybe this is called "map properties of one class to several tables"
Can the value variable of JClass be mapped to all 6 columns?


Look at <join> mapping in the H3 docs if you want to map all 6 columns to a single Object.

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 24, 2005 11:28 am 
Newbie

Joined: Sun Oct 23, 2005 8:33 pm
Posts: 4
well, I just tried <join>.
First, it looks like <join> requires <key> which defines foreign key in the joined table.

Second, H throws this exception: "duplicate property mapping: value"

does this mean that a single instance variable cant be mapped to multiple columns?


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.