Hi, I was hoping someone might be able to shed some light on something for me. I'm migrating some code of mine to hibernate-annotations as a learning excercise. I'm trying to map a @CollectionOfElements using a Map field. I can get this working if the value type of the Map is annotated as an @Entity, but I believe I should be able to do it if it is @Embeddable as well. I can't find any direct examples, but the hibernate-annotations docs contain an example using a Set rather than a Map.
Hibernate version: 3.1
Mapping documents: hibernate.cfg.xml
Code:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.HSQLDialect</property>
<mapping class="scrabble.db.hibernate31.Tile"/>
<mapping class="scrabble.db.hibernate31.TileSetImpl"/>
</session-factory>
</hibernate-configuration>
Persistent Classes:Code:
@Entity(access = AccessType.FIELD)
@Table(name = "TileSet")
class TileSetImpl implements TileSet, Serializable
{
@Id(generate = GeneratorType.NONE)
@Column(length = 16)
private Locale locale;
@CollectionOfElements
@JoinTable(table = @Table(name="Tile"), joinColumns = @JoinColumn(name = "tileset_locale"))
@MapKey(name = "letter")
private Map<String, Tile> tiles;
public Locale getLocale()
{
return locale;
}
}
Code:
@Embeddable(access = AccessType.FIELD)
class Tile implements Serializable
{
@Column(name = "tileset_locale", nullable = false, length = 16)
private Locale tilesetLocale;
@Column(nullable = false, length = 2)
private String letter;
@Column(nullable = false)
private int frequency;
@Column(nullable = false)
private int score;
public Locale getTilesetLocale()
{
return tilesetLocale;
}
public String getLetter()
{
return letter;
}
public int getFrequency()
{
return frequency;
}
public int getScore()
{
return score;
}
public boolean equals(Object o)
{
...
}
public int hashCode()
{
...
}
}
Because the Tile class is completely subordinate to the TileSetImpl class (i.e. external code only interacts with the methods of the TileSet interface it seems logical (to me anyway) to have it as an @Embeddable rather than a full-blown @Entity.
I'm simply trying to run the hbm2ddl Ant task and get the error
Code:
org.hibernate.AnnotationException: Associated class not found: scrabble.db.hibernate31.Tile
.
As I say I can get this to work with the Tile class written as an @Entity with an inner PK class comprised of the tilesetLocale and letter fields.[/code]