Hi to all!
I'm new to H8 and I've a strange trouble.
I have a simple Many-To-One Relationship:
Street 1 - N
Street numberIn
Streets.java I have:
Code:
@Entity
@Table(name = "STREETS")
public class Streets implements java.io.Serializable {
// ... various fields ...
private List<StreetNumbers> streetNumbers = new ArrayList<StreetNumbers>(0);
// ..
@OneToMany(mappedBy="street") // It points to a "street" property in StreetNumbers.java
public List<StreetNumbers> getStreetNumbers() {
return this.streetNumbers;
}
public void setStreetNumbers(List<StreetNumbers> streetNumbers) {
this.streetNumbers = streetNumbers;
}
}
In
StreetNumbers.java I have:
Code:
@Entity
@Table(name = "STREET_NUMBERS")
public class StreetNumbers implements java.io.Serializable {
// ... various fields ...
private Streets street;
// ...
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_STREET", nullable = false, insertable = false, updatable = false)
public Streets getStreet() {
return this.street;
}
public void setStreets(Streetsstreet) {
this.street= street;
}
}
But this implementation raises the following exception:
Caused by: org.hibernate.MappingException: Could not determine type for: java.util.List, for columns: [org.hibernate.mapping.Column(StreetNumbers)] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
at org.hibernate.mapping.Property.isValid(Property.java:185)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:918)
at it.eng.elisa.coop.variazioni.acsor.persistence.SessionFactoryManager.<clinit>(SessionFactoryManager.java:34)
... 3 more
But if I put the @OneToMany and @ManyToOne annotations on the properties instead of the fields, it works fine:
StreetCode:
@OneToMany(mappedBy="street")
private List<StreetNumbers> streetNumbers= new ArrayList<StreetNumbers>(0);
StreetNumbers.javaCode:
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "ID_STREET", nullable = false, insertable = false, updatable = false)
private Streets street;
I don't understand this behaviour.
PS:
I have the same problem with the @Column annotations.
If I put them on the getter, H8 uses the name of property to access to the DB causing an error.
If I put them on the class field, H8 uses the name set in @Column(name = ...).
Thanks in advance!