-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: saveOrUpdate + HSQLDB = timing problem?
PostPosted: Fri Jan 15, 2010 5:47 pm 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
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!


Top
 Profile  
 
 Post subject: Re: saveOrUpdate + HSQLDB = timing problem?
PostPosted: Sun Jan 17, 2010 7:28 am 
Beginner
Beginner

Joined: Mon Jan 04, 2010 2:52 pm
Posts: 30
This is the solution:
Code:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
session.saveOrUpdate(prj);
tx.commit();
session.connection().createStatement().execute("CHECKPOINT");
session.close();


Thanks to Fred Toussi from hsqldb-user.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.