-->
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: How to map a custom key
PostPosted: Tue Sep 21, 2004 9:45 am 
Newbie

Joined: Tue Sep 21, 2004 9:23 am
Posts: 5
Hi,

i`m currently trying to map a legacy DB in hibernate. Everything went pretty smooth until now. I encountered a situation to which I can`t find a proper solution.

The situation :
-----------------
| Table A |
-----------------
| id | SomeInfo |
-----------------

--------------------
| Table B |
--------------------
| i | d | SomeInfo |
--------------------

Example :
id = 1020 --> relation to B

i = 10
d = 20
i+d = 1020 --> relation to A

I`ve tried to create a custom key and use the key in both maps.

MyKey example :

public class MyKey implements Serializable
{
private String i;
private String d;

public MyKey(String i, String d)
{
this.i = i;
this.d = d;
}

public ProductCode(String id)
{
this.i = id.subString(0, 1);
this.i = id.subString(1, 2);
}

public ProductCode()
{
}
}

MyKey doesn`t map with mapgenerator because it`s missing a unique ID (which I understand).

What is the right way to solve this ? And could someone give an example of how the hibernate mappings for Table A and Table B should look like?


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.