I'm using Hibernate 3.0.5. I want to map the following classes:
Code:
interface State {
public String getName();
public State[] getNextStates();
}
class BaseState implements State {
private Long id;
private String name;
private State[] nextStates;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public State[] getNextStates() {
return nextStates;
}
public void setNextStates(State[] nextStates) {
this.nextStates = nextStates;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}
class Item {
private Long id;
private String name;
private State state;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public State getState() {
return state;
}
public void setState(State states) {
this.states = state;
}
}
with the following mapping:
Code:
<hibernate-mapping>
<class table="state" name="BaseState">
<id column="state_id" name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" length="60" type="string" column="name"/>
</class>
<class table="item" name="Item">
<id column="item_id" name="id">
<generator class="native"/>
</id>
<property name="name" not-null="true" length="60" type="string" column="name"/>
<many-to-one column="state_id" name="state" class="State"/>
</class>
</hibernate-mapping>
But I get an error:
Quote:
An association from the table items refers to an unmapped class: State
So I added:
Code:
<class table="state" name="State">
</class>
But now the State's class mapping won't validate because the
class element needs an
id element.
My question is: How can I make my
Item class have a
State(the interface, not the implementation) member, without adding
getId() to
State's interface?
Thanks in advance,
Daniel Serodio