I am using hibernate 4.1.9.
I am getting weird behavior from it.
This is what I have:
Code:
@Entity
@Table(name = "Container")
public class Container implements Serializable {
private Integer containerID;
private Set<ContainerIdentifier> containerIdentifiers;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(unique = true, nullable = false)
public Integer getContainerID() {
return this.containerID;
}
public void setContainerID(Integer containerID) {
this.containerID = containerID;
}
@OneToMany(mappedBy = "container", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
public Set<ContainerIdentifier> getContainerIdentifiers() {
return this.containerIdentifiers;
}
public void setContainerIdentifiers(
Set<ContainerIdentifier> containerIdentifiers) {
this.containerIdentifiers = containerIdentifiers;
}
}
Code:
@Entity
@Table(name="ContainerIdentifiers")
public class ContainerIdentifier implements Serializable {
private Integer containerIdentifiersID;
private Container container;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(unique=true, nullable=false)
public Integer getContainerIdentifiersID() {
return this.containerIdentifiersID;
}
public void setContainerIdentifiersID(Integer containerIdentifiersID) {
this.containerIdentifiersID = containerIdentifiersID;
}
@ManyToOne(fetch=FetchType.LAZY)
@JoinColumn(name="containerID", nullable=false)
public Container getContainer() {
return this.container;
}
public void setContainer(Container container) {
this.container = container;
}
}
For some reason hibernate inserts first the ContainerIdentifiers and fails on non-null transient entity Container instead of starting with the Container.
Any clues?
Thanks