Wenn ich das nullable auf true setzt läuft es, ich bekomme in der Many
Tabelle jedoch Null Referenzen.
Wo ist mein Fehler?
Viele Grüße Tom
org.hibernate.PropertyValueException: not-null property references a
null or transient value: de.javacus.rias.beans.ManyToOneCrud.oneToManyCrud
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:95)
at
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:313)
at
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:204)
//snip
session.beginTransaction();
OneToManyCrud oneMany = new OneToManyCrud("second");
oneMany.getMany().add(new ManyToOneCrud("test1"));
oneMany.getMany().add(new ManyToOneCrud("test2"));
oneMany.getMany().add(new ManyToOneCrud("test3"));
session.save(oneMany);
session.getTransaction().commit();
//snip
@Entity
@Table(name = "oneToManyCruds")
public class OneToManyCrud
{
@Id
@GeneratedValue
@Column(name = "id")
private int id;
private String one;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "oneToManyCrud")
private Set<ManyToOneCrud> many = new HashSet<ManyToOneCrud>();
public OneToManyCrud()
{
}
public OneToManyCrud(String one)
{
super();
this.one = one;
}
es folgen Getter und Setter
@Entity
@Table(name = "manyToOneCruds")
public class ManyToOneCrud
{
@Id
@GeneratedValue
@Column(name = "id")
private int id;
private String many;
@ManyToOne
@JoinColumn(nullable = false)
private OneToManyCrud oneToManyCrud;
public ManyToOneCrud()
{
}
public ManyToOneCrud(String many)
{
super();
this.many = many;
}
es folgen Getter und Setter
Gruß Tom
Thomas Grabietz schrieb: