All,
I am new to Hibernate (version 3.2.3.ga). I need to make changes to an exsisting application which was written with Hibernate. The appl is working fine before I added my change.
In a nutshell, there are two objects DMStagingTable and DMStagingIndex.
DMStagingTable._indexes is a set of DMStagingIndex instances.
My objective is to delete DMStagingIndex objects and update its persistent counter parts.
I had tried:
/////// Version 1
remove DMStagingIndex from the set DMStagingTable._indexes
call session.saveOrUpdate(DMStagingTable) // legacy call; maybe I should not be calling it.
the call does not bomb but it does not update the database
/////// Version 2
call session.delete(DMStagingIndex) // my idea
remove DMStagingIndex from the set DMStagingTable._indexes
call session.saveOrUpdate(DMStagingTable) // legacy call
the call bombs with HibernateOptimisticLockingFailureException
I did not make the call to saveOrUpdate((DMStagingTable)) but it is from existing code; I think it is trying to update the objects for different reasons. I don't think I can avoid this call.
Summary:
Any pointer will be greatly appreciated. So far working with Hibernate is quite painfull. I have been reading the Hibernate documentation, but I have not been able to solve this problem on my own. I also have the book java persistence with Hibernate. It has a lot of information, but by combinating JPAPI and Hibernate, it makes thing unnecessary complicated. Please suggest other essential readings; my goal is just to master Hibernate for now; Java Persistence can wait. There must be some trick in delete objects and make the state consistent with both memory and database instances.
Thanks,
Steve
///////////////////////////////////////////////////////////////////////////
//details of the relationship between DMStagingTable and DMStagingIndex==
///////////////////////////////////////////////////////////////////////////
(1)
public class DMStagingTable
@OneToMany(targetEntity=DMStagingIndex.class, cascade=CascadeType.ALL, fetch=FetchType.EAGER, mappedBy="stagingTable")
...
private Set<DMStagingIndex> _indexes = new HashSet<DMStagingIndex>();
(2)
public class DMStagingIndex
@ManyToOne(targetEntity=DMStagingTable.class, cascade={CascadeType.ALL})
@ManyToMany(fetch=FetchType.EAGER, targetEntity=DMStagingColumn.class)
@JoinTable(name="DM_STAGING_INDEX_COLUMNS",
joinColumns=@JoinColumn(name="STAGING_INDEX_ID", referencedColumnName="ID"),
inverseJoinColumns=@JoinColumn(name="STAGING_COLUMN_ID", referencedColumnName="ID"))
|