-->
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: Lookup Table - mapping class property to another table
PostPosted: Wed Dec 07, 2005 9:52 am 
Newbie

Joined: Wed Dec 07, 2005 8:20 am
Posts: 10
Hi all,

I'm a newbie and have following problems.

I use Many to One association but I don't want to have 2 Different Objects

Let me use the example on the Reference Doc Chapter 8.2.1, with some modification

Tables:

create table Person (
personId bigint not null primary key,
name VARCHAR(50),
addressId bigint not null REFERENCES Address (addressId)
)

create table Address (
addressId bigint not null primary key,
street VARCHAR(50)
)


I want to have only Person Object

Class Person{

private Integer personId;
private String name;
private String street; //no Address Object association
...
}


the uncomplete mapping file:
<class name="Person">
<id name="id" column="personId">
<generator class="native"/>
</id>
<property name="name" column="name" type="string" not-null="true"/>

<!-- PROBLEM: map normal value to a column in DIFFERENT TABLE -->
<property name="street" type="string" not-null="true"/>


</class>


The Address Table is just a Lookup table with 1 column of VARCHAR....

If I follow the NORMAL many to one association, then I have to create an Object fo every LOOKUP Table, and then map the Object as Attribute of the Class. Somehow I believe that this is too complicated to write, specially if you have dozens of lookup table value....

Can this be done in Hibernate??

I tried the <JOIN> element, but no success, specially because the JOIN element's KEY needs that there is a foreign key IN the ADDRESS table, which reference to the PK of the PERSON Table, but on my case the PERSON TABLE have a FK to the ADDRESS TABLE.


Thank you very much for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 30, 2005 1:30 pm 
Beginner
Beginner

Joined: Thu Dec 29, 2005 12:08 pm
Posts: 31
Location: Acton, MA
Have you found a solution for this? I posted the same topic, and no one could answer it either.

Thanks,
Laird


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 04, 2006 11:23 am 
Newbie

Joined: Wed Dec 07, 2005 8:20 am
Posts: 10
Nope...

I rearrange my mapping, and try to use different schema


Top
 Profile  
 
 Post subject: I've got the same problem...
PostPosted: Fri Jan 06, 2006 10:33 am 
Newbie

Joined: Fri Jan 06, 2006 10:22 am
Posts: 1
Unfortunately in my case, the mapping table is more like an enum. It looks sort of like this:

Code:
create table item (
id int,
color_id int,
...
)

create table color_lookup (
id int,
color char(20)
)

I would like to be able to have the Item bean simply have a color property that is a simple string (i,e,,
Code:
public class Item {
  public String getColor()
  {...}
...
}
), since the colors are seldom updated (we will do that by hand with an SQL insert). On the other hand, they will be updated often enough that I don't want an enum and a recompile every time we do...
Any ideas?

Fedora


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 12:29 pm 
Newbie

Joined: Fri Dec 30, 2005 10:51 am
Posts: 3
Actually, you folks aren't the only ones with this problem.

I have to use a schema that I cannot change (is "imposed" on me), and I need to have an object with some string anfd integer properties that map to two different tables.

I have been studying documentation and Hibernate books for quite some time; there is plenty on Joins and plenty on associations, but nothing anywhere that speaks of this particular situation.

Have we found a Hibernate limitation? Or are we missing something?

Does anyone have an answer to this question???

_________________
Factor Three


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 06, 2006 1:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
<join>

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 15, 2006 7:20 pm 
Newbie

Joined: Wed Dec 07, 2005 8:20 am
Posts: 10
<join> is not what I want... since I wrote it that it didn't work

and the end... I create a Class for the all attribute.
The Class is then mapped to the lookup table...

works well... :-)


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.