Having a problem with a OneToMany-mapping. After doing a find, the collection-field with the OneToMany-mapping has the right amount of objects in it but they are all the same.
For example, if one "Utlamningsstalle" is connected to 4 different "Postnummer", i get a collection containing 4 "Postnummer" objects but they are identical (the first "Postnummer" the database returns times 4).
I've looked at the SQL hibernate executes and it is correct. However the collection is not populated the way I imagined it would.
What have I missed here?
These are my entities (w/o getters, setters etc.):
Code:
@Entity
@Table(name="UTLSTALLE")
public class Utlamningsstalle {
@Id
@Column(name="INTRID_UTLST")
long intressentid;
@Column(name="UTLSTID")
String utlamningsstalleid;
@Column(name="UTLSTBEN")
String benamning;
String datumfom;
String datumtom;
String landkod;
String sorteringskod;
String hanteringsstalle;
@OneToMany(mappedBy="utlamningsstalle")
Collection<Postnummer> postnummer;
}
Code:
@Entity
@Table(name="UTLST_POSTNR")
public class Postnummer {
@Id
@Column(name="INTRID_UTLST" )
long intressentid;
@Column(name="POSTNR")
String postnummer;
String datumfom;
String datumtom;
String osakerjn;
@ManyToOne
@JoinColumn(name="INTRID_UTLST", insertable = false, updatable = false)
Utlamningsstalle utlamningsstalle;
}