-->
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: Trying to persist a Hashtable
PostPosted: Wed Sep 08, 2010 5:10 pm 
Newbie

Joined: Wed Sep 08, 2010 4:46 pm
Posts: 1
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.


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.