Hi,
recently I changed from using .hbm.xml files to using annotations and now a particular association is giving me headaches when comitting transactions that store new objects in the database.
In particular this is a bidirectional One-To-Many association with the Many-Side being the owner. I'm trying to store the new objects of both classes within the same transactions and always get an error about violating the foreign key constraint of the many-table, because the object in the one-table doesn't exist.
The 2 tables involved are media and logentry and it seems that for some reason hibernate wants to persist logentry before media. The association is 1 media has multiple logentries. I already checked that when I add a new logentry to media I also set the media attribute of that logentry properly. And the Many-To-One annotation in logentry uses a CascadeType.ALL.
The 2 classes annotations are this:
Code:
@Entity
public class Media implements java.io.Serializable
{
@Id @GeneratedValue
private int id;
@OneToMany( mappedBy="media" )
private Set<LogEntry> logEntries = new HashSet<LogEntry>(0);
}
@Entity
@Table (name="log")
public class LogEntry
{
@Id @GeneratedValue
private int id;
@ManyToOne( cascade = {CascadeType.ALL} )
private Media media;
}