-->
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.  [ 4 posts ] 
Author Message
 Post subject: Help! Problem describing Map using annotations
PostPosted: Sun Sep 04, 2005 10:12 am 
Newbie

Joined: Sun Sep 04, 2005 9:27 am
Posts: 2
Hello,
I have following classes
Code:
interface IDeviceTypeProperty;
interface IDeviceType;
interface IDevice;

@Entity
class DeviceTypeProprty implements IDeviceTypeProperty {
  @Id(generate=GeneratorType.AUTO)
  public Long getId() {...}
  @Basic
  public String getName() {...}
  ....
}
@Entity
class DeviceType implements IDeviceType {
  @Id(generate=GeneratorType.AUTO)
  public Long getId() {...}
  @Basic
  public String getName() {...}
  @OneToMany(cascade=CascadeType.ALL,
                      targetEntity=DeviceTypeProperty.class)

  public Set<IDeviceTypeProperty> getProperties() {...}

 
  ....
}
@Entity
class Device implements IDevice {
  @Id(generate=GeneratorType.AUTO)
  public Long getId() {...}
  @Basic
  public String getName() {...}
  [b]
  @OneToMany
  @MapKey
  public Map<IDeviceTypeProperty, Serializable> getProperties() {...}
  [/b]
}


When I am running the sample code I am getting
Quote:
org.hibernate.MappingException: Association references unmapped class: java.lang.Serializable


Then I've created another class
Code:
interface IPropertyValue;
@Entity
class PropertyValue implements IPropertyValue {
  @Id(generate=GeneratorType.AUTO)
  public Long getId() {...}
  @Basic
  public Serializable getValue() {...}
}

and modified the getProperties in Device class as following
Quote:

@OneToMany(targetEntity=PropertyValue.class)
@MapKey
public Map<IDeviceTypeProperty, IPropertyValue> getProperties() {...}


but then I am getting following error
Code:
10:02:05,301 DEBUG SchemaUpdate:150 - create table MediumChanger_PropertyValue (MediumChanger_id bigint not null, properties_id bigint not null, primary key (MediumChanger_id, id))
10:02:05,304 ERROR SchemaUpdate:156 - Unsuccessful: create table MediumChanger_PropertyValue (MediumChanger_id bigint not null, properties_id bigint not null, primary key (MediumChanger_id, id))
10:02:05,305 ERROR SchemaUpdate:157 - Syntax error or access violation message from server: "Key column 'id' doesn't exist in table"


Of course I would prefer to use Serializable as a value but if it doesn't work I can fallback to PropertyValue as value for the map.

I was able to do such structure with XDoclet and Hibernate2 like this:
Code:
  /**

   * Returns metada values Map

   * @return Map

   * @hibernate.map table="metadata_value"

   * @hibernate.collection-key column="asset_id"

   * @hibernate.index-many-to-many column="metadata_id" class="MetaDataDef"

   * @hibernate.collection-element column="value" type="serializable"

   */


Unfortunately I was unable to find any examples of using java.util.Map with annotations except the one mentioning in hibernate-annotations documentations. But the one is not working :(
How can I do such thing using Java Annotations?
I am using MySQL 4.1, Hibernate3.1Beta1, HibernateAnnotations3.1Beta4

Thanks a lot.[/quote][/code][/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 5:03 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
maps having an entity as a key are not supported yet.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 1:34 pm 
Newbie

Joined: Sun Sep 04, 2005 9:27 am
Posts: 2
That's sad
Then what kind of performance penalty following structure will have against the Map
Code:
Set <PersistentKeyValue>

class PersistentKeyValue
{
    public PersistentKey getKey();
    public String getValue();
}


Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 09, 2005 6:14 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
None I guess, but I didn't think too long on that problem

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.