-->
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 single property to "join table"
PostPosted: Mon Sep 26, 2011 4:32 am 
Newbie

Joined: Mon Sep 26, 2011 4:17 am
Posts: 1
Hi,
I have following problem... I have POJO object with simple fields like
Code:
String property1;
String property2;
...
// getters/setters ...

Problem is, that in DB property1, property2... HAS TO BE mapped to standalone table (let's say StringPropertyTable), with foreign key to "parent table", key = "property1"/"property2", value = value of the property. How can I do that mapping in Hibernate? I thought discriminator is the key for this problem, but I can not figure out, how can I tell Hibernate that this one-to-many relation filtered by "key" is in fact one-to-one relation... POJO object and DB schema cannot be modified! Thanks for any suggestions.


Top
 Profile  
 
 Post subject: Re: Mapping single property to "join table"
PostPosted: Mon Sep 26, 2011 2:18 pm 
Newbie

Joined: Mon Sep 26, 2011 2:07 pm
Posts: 3
I'm thinking this should work just fine:

@Entity
class MainEntity {
.
.
.

@OneToMany
@JoinColumn(name="whatever")
private StringPropertiesEntity stringProperties ;

.
.
.
}

class StringPropertiesEntity {

@(Annotations)
private int id ;

@Column(name="key")
private String key ;

@Column(name="value")
private String value ;

/// getters/setters ///
}


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.