hello,
I have a class Project and a class SequenceList, with a OneToMany relation
in between. When I call session.saveOrUpdate(project) and immediately
afterwards close the application, the instances on the many side are not
updated (deleted or inserted).
Do I need to shut down HSQLDB beyond what hibernate does?
I am using:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(prj);
tx.commit();
session.close();
I am using HSQLDB 1.8.1.1 with hibernate-3.3.2.
here are some details:
Code:
@Entity
@Table(name="projects")
public class Project implements Iterable<SequenceList>, PropertyChangeListener {
@Id
private final Long id = 1L; // Singleton semantics
@Column
public int version = 1; // hibernate cannot handle final fields
[...]
@OneToMany(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
@org.hibernate.annotations.IndexColumn(name="indexcol")
@org.hibernate.annotations.Cascade({org.hibernate.annotations.CascadeType.ALL,
org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
private List<SequenceList> hitlists;
[...]
@Entity
@Table(name="sequencelists")
public class SequenceList implements Iterable<Sequence> {
@Id
@GeneratedValue
protected Long id;
@Column
public int version = 1; // hibernate cannot handle final fields
@Column
protected String name;
[...]
Concerning the Project class:
- the primary key is always 1L because I use a separate HSQLDB database für
each Project
Concerning the Project.hitlists variable:
- I needed to use FetchType.EAGER because I close the session right after
loading a Project (otherwise: LazyInitializationException)
- @org.hibernate.annotations.IndexColumn(name="indexcol") was necessary
for eager fetching (otherwise: MultipleBagFetchException)
- without the CascadeType.DELETE_ORPHAN, a SequenceList is not deleted
in the database when I remove it from the hitlist collection and
run saveOrUpdate(project)
Thanks in advance!