-->
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: Mapping java.util.Map with non-entity key
PostPosted: Fri Sep 09, 2011 3:12 am 
Newbie

Joined: Fri Sep 09, 2011 2:55 am
Posts: 1
I have a following database structure:
Code:
BASE_OBJECT                 ATTRIBUTE_VALUE                   ATTRIBUTE
-----------------           ---------------------             ---------------
PK BASE_OBJECT_ID<--\       PK ATTRIBUTE_VALUE_ID        /--->PK ATTRIBUTE_ID
                     \------FK BASE_OBJECT_ID           /        NAME
                            FK ATTRIBUTE_ID------------/
                               VALUE


Is it possible for BaseObject to get his attribute values through a map by ATTRIBUTE.NAME key?
Code below should explain what am i want (see BaseObject.attributes):
Code:
@Entity
@Table(name = "BASE_OBJECT")
class BaseObject {
   @Id
   @Column(name = "BASE_OBJECT_ID")
   private Integer objectID;
   
   // How can i do this?
   // Keys are Attribute.name, joined by AttributeValue.baseObject
   private Map<String, AttributeValue> attributes;
   
   // getters/setters
}

@Entity
@Table(name = "ATTRIBUTE")
class Attribute {
   @Id
   @Column(name = "ATTRIBUTE_ID")
   private Integer attributeID;
   
   @Column(name = "NAME")
   private String name;
   
   // getters/setters
}

@Entity
@Table(name = "ATTRIBUTE_VALUE")
class AttributeValue {
   @Id
   @Column(name = "ATTRIBUTE_VALUE_ID")
   private Integer attributeValueID;
   
   @Column(name = "VALUE")
   private String value;
   
   @ManyToOne
   @JoinColumn(name = "ATTRIBUTE_ID")
   private Attribute attribute;
   
   @ManyToOne
   @JoinColumn(name = "BASE_OBJECT_ID")
   private BaseObject baseObject;
   
   //getters/setters
}


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.