Can someone explain how mapping a Map collection of entities within an entity 
works and how it should be done?  Or perhaps point me to documentation on the 
subject?  So far, I've found only this:
http://www.hibernate.org/hib_docs/annotations/reference/en/html/entity.html#entity-mapping-association-collections
...which looks promising, but I'm not sure how to set up my entities or if it 
is intended to work how I am thinking it will.

Background on what I'm trying to do: I have entities that have n properties 
that I am storing as key/value pairs.  Currently an entity has a collection of 
properties stored in a Set.  Something like this...
@Entity
  | public class ItemA {
  |   private long id;
  |   private Set<Property> properties;
  | 
  |   @Id(generate = GeneratorType.AUTO)
  |   public long getId() {
  |     return id;
  |   }
  |   public void setId(long id) {
  |     this.id = id;
  |   }
  | @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER)
  |   @JoinTable(
  |       table = @Table(name = "ItemA_Properties"),
  |       joinColumns = @JoinColumn(name = "Property_id", referencedColumnName 
= "id"),
  |       inverseJoinColumns = @JoinColumn(name = "ItemA_id", 
referencedColumnName = "id")
  |   )
  |   public Set<Property> getProperties() {
  |     return properties;
  |   }
  |   public void setProperties(Set<Property> properties) {
  |     this.properties = properties;
  |   }
  | }
  | 
  | @Entity
  | public class Property {
  |     private long id;
  |     private String propKey;
  |     private String propValue;
  |    
  |     @Id(generate = GeneratorType.AUTO)
  |     public long getId() {
  |         return id;
  |     }
  |     public void setId(long id) {
  |         this.id = id;
  |     }
  |     public String getPropKey() {
  |         return propKey;
  |     }
  |     public void setPropKey(String propKey) {
  |         this.propKey = propKey;
  |     }
  |     public String getPropValue() {
  |         return propValue;
  |     }
  |     public void setPropValue(String propValue) {
  |         this.propValue = propValue;
  |     }
  | }

This works simply enough, but what would make more sense is if the "properties" 
collection was a Map.  Simply changing the "properties" collection to a 
"Map<String, Properties>" and setting a "@MapKey(name="propKey")" annotation 
doesn't seem to be the answer.  I get the feeling I'm missing something obvious.

Thanks for any help on mapping Maps that can be offered,
Jonn

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3915660#3915660

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3915660


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to