Hibernate generates an unknown field using the following mapping. Any idea?
hibernate-3.2.0.CR2, hibernate-annotations-3.2.0.CR1
Mysql 5.0.18
Quote:
Tables
Code:
person (int id)
attribute(int id)
person_attribute (int person_id, int attribute_id)
Code:
@Entity
public class Attribute implements java.io.Serializable
{
private int id;
private Map<Integer, Person> persons = new HashMap<Integer, Person>(0);
@ManyToMany(mappedBy = "attributes")
@MapKey(name="id")
public Map<Integer, Person> getPersons()
{
return this.persons;
}
}
Code:
@Entity
public class Person implements java.io.Serializable
{
private int id;
@ManyToMany
@JoinTable(name="person_attribute",
joinColumns={@JoinColumn(name="person_id",referencedColumnName="id")},
inverseJoinColumns={@JoinColumn(name="attribute_id", referencedColumnName="id")})
@MapKey(name="id")
public Map<Integer, Attribute> getAttributes()
}
Code:
Attribute attribute = (Attribute) s.load(Attribute.class, 1);
Map<Integer, Person> persons = attribute.getPersons();
for (Person person : persons.values()){
out.println(person.getId());
}
Person person = (Person) s.load(Person.class, 1);
Map<Integer, Attribute> attributes = person.getAttributes();
for (Attribute attribute1 : attributes.values()){
out.println(attribute1.getId());
}
/* load collection bug.Attribute.persons */ select persons0_.attribute_id as attribute2_1_, persons0_.person_id as person1_1_, persons0_.id as formula1_1_, person1_.id as id0_0_ from person_attribute persons0_ left outer join hibernatebug.person person1_ on persons0_.person_id=person1_.id where persons0_.attribute_id=?
[ 0] WARN - ate.util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22
[ 0] ERROR - ate.util.JDBCExceptionReporter - Unknown column 'persons0_.id' in 'field list'
/* load collection bug.Person.attributes */ select attributes0_.person_id as person1_1_, attributes0_.attribute_id as attribute2_1_, attributes0_.id as formula0_1_, attribute1_.id as id1_0_ from person_attribute attributes0_ left outer join hibernatebug.attribute attribute1_ on attributes0_.attribute_id=attribute1_.id where attributes0_.person_id=?
[ 0] WARN - ate.util.JDBCExceptionReporter - SQL Error: 1054, SQLState: 42S22
[ 0] ERROR - ate.util.JDBCExceptionReporter - Unknown column 'attributes0_.id' in 'field list'