Hi,
I'm relatively new to Hibernate, and I'm using (according to the logs) Hibernate 3.5.3-Final with Java 1.6 and annotations 3.2.0.Final.
In one class I have a Hashtable<String,Integer> property which I wish to persist, but I'm getting the error:
Caused by: org.hibernate.AnnotationException: Use of @OneToMany or @ManyToMany targeting an unmapped class: uk.org.glendale.worldgen.civ.facility.Facility.requirementList[java.lang.Integer]
The current iteration of the class is:
Code:
@Entity
public class Facility {
  @Id @GeneratedValue @Column(name="id") private int id;
  @Column(name="name") private String name;
  @Enumerated(EnumType.STRING)
  @Column(name="type")   private FacilityType type;
  ...
  @OneToMany @JoinTable(name="facility_requirements")
  @MapKeyColumn(name="facility_id")
  @AttributeOverrides({
    @AttributeOverride(name="key", column=@Column(name="code")),
    @AttributeOverride(name="value", column=@Column(name="value"))
  })
  private Map<String,Integer> requirementsList;
}
It's the requirementsList field which is causing problems, and I'm not sure exactly what annotations are required. The database tables look something like (some columns removed for brevity):
Code:
mysql> describe facility;
+-------------+-------------+------+-----+---------+----------------+
| Field       | Type        | Null | Key | Default | Extra          |
+-------------+-------------+------+-----+---------+----------------+
| id          | int(11)     | NO   | PRI | NULL    | auto_increment |
| name        | varchar(64) | YES  | UNI | NULL    |                |
| type        | varchar(16) | YES  |     | NULL    |                |
...
+-------------+-------------+------+-----+---------+----------------+
10 rows in set (0.00 sec)
mysql> describe facility_requirements;
+-------------+-------------+------+-----+---------+-------+
| Field       | Type        | Null | Key | Default | Extra |
+-------------+-------------+------+-----+---------+-------+
| facility_id | int(11)     | NO   | MUL | NULL    |       |
| code        | varchar(12) | NO   |     | NULL    |       |
| value       | int(11)     | NO   |     | NULL    |       |
+-------------+-------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
So the hashtable key needs to map to 'code', and the value to 'value'. Can anyone help with the right annotation declaration I need? I've done a similar thing before by creating a new class, and referencing it as a List, but I really don't need any more functionality on the Java side than what a simple hashtable<String,Integer> gives me, so would prefer to do it 'right' this time.
To complicate things, the types are actually meant to be <CommodityType,Integer>, where CommodityType is an enum. I've simplified it to a String for now, whilst trying to get it to work.
After this, a second Map needs to be added, which takes a class (already persisted elsewhere) as the key, but this can wait until later.
Any help greatly appreciated,
Thanks,
Sam.