Hi,
I am using parent child relationship, similar to Category <> Category and Category <> Item found in caveatemptor
I am trying to delete a Object even after deleting its references from the Object Tree. Still does not work!
The code base is here
Person class (similar to Category)
Code:
@Entity(access = AccessType.FIELD)
public class Person {
@Id
@Column(length=100)
public String ID;
public String Name;
@ManyToOne(cascade = {CascadeType.CREATE, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name="ParentPersonID")
public Person ParentPerson = null;
@OneToMany(cascade = {CascadeType.CREATE, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn(name="ParentPersonID")
public Set<Person> Children = new HashSet();
@OneToMany(cascade = {CascadeType.CREATE, CascadeType.MERGE}, fetch=FetchType.EAGER)
@JoinColumn(name="PersonID")
public Set<Degree> Degrees = new HashSet();
public Person() {
}
public Person(String _Name) throws Exception {
ID = IDGen.generateID();
Name = _Name;
}
public void addChild(Person _Person) {
_Person.ParentPerson = this;
Children.add(_Person);
}
public void addDegree(Degree _DegreeObj) {
_DegreeObj.PersonObj = this;
Degrees.add(_DegreeObj);
}
}
Degree class (similar to Item)
Code:
@Entity(access = AccessType.FIELD)
public class Degree {
@Id
@Column(length=100)
public String ID;
public String Name;
@ManyToOne(cascade = {CascadeType.CREATE, CascadeType.MERGE}, fetch = FetchType.EAGER)
@JoinColumn(name="PersonID")
public Person PersonObj = null;
public Degree() {
}
public Degree(String _Name) throws Exception {
ID = IDGen.generateID();
Name = _Name;
}
}
The code that uses it:
Code:
Person Senior;
Person Junior;
try {
DatabaseManager.beginTransaction();
Senior = new Person("Senior");
Senior.addDegree(new Degree("Senior Degree 1"));
Senior.addDegree(new Degree("Senior Degree 2"));
Junior = new Person("Junior");
Junior.addDegree(new Degree("Junior Degree 1"));
Junior.addDegree(new Degree("Junior Degree 2"));
Senior.addChild(Junior);
DatabaseManager.getSession().saveOrUpdate(Senior);
DatabaseManager.commitTransaction();
} catch (Exception ExceptionObj) {
DatabaseManager.rollbackTransaction();
throw ExceptionObj;
} finally {
DatabaseManager.closeSession();
}
try {
DatabaseManager.beginTransaction();
//Remove the ONLY link in the Object Graph!
Senior.Children.remove(Junior);
DatabaseManager.getSession().delete(Senior);
DatabaseManager.commitTransaction();
} catch (Exception ExceptionObj) {
DatabaseManager.rollbackTransaction();
ExceptionObj.printStackTrace();
} finally {
DatabaseManager.closeSession();
}
The exception I get is as follows:
Code:
Caused by: org.hibernate.exception.GenericJDBCException: could not delete: [com.thoughtcircle.parent.Person#103365688_1106551811578]
at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:82)
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:70)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.persister.BasicEntityPersister.delete(BasicEntityPersister.java:1898)
at org.hibernate.persister.BasicEntityPersister.delete(BasicEntityPersister.java:2025)
at org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:44)
at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.impl.ActionQueue.executeActions(ActionQueue.java:142)
at org.hibernate.event.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:255)
at org.hibernate.event.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:26)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:814)
at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:75)
at com.thoughtcircle.database.DatabaseManager.commitTransaction(DatabaseManager.java:136)
... 16 more
Caused by: org.firebirdsql.jdbc.FBSQLException: GDS Exception. 335544333. internal gds software consistency check (partner index description not found (175))
at org.firebirdsql.jdbc.AbstractPreparedStatement.internalExecute(AbstractPreparedStatement.java:503)
at org.firebirdsql.jdbc.AbstractPreparedStatement.executeUpdate(AbstractPreparedStatement.java:144)
at com.mchange.v2.sql.filter.FilterPreparedStatement.executeUpdate(FilterPreparedStatement.java:71)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:22)
at org.hibernate.persister.BasicEntityPersister.delete(BasicEntityPersister.java:1881)
... 25 more
What could the problem be? Any solution?
Also should there be a change in the class "AnnotationBinder" in the function "getCascadeStrategy(CascadeType[] cascades)" (line # 1279). We include all-delete-orphan as a cascade strategy for CascadeType UPDATE and REMOVE?