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]