Deadlock using Java API

Hi there,
I am having this problem on deadlock(or at least i think thats what it is!) and have checked out the rest of the messages on this forum if someone else has faced this same problem but apparently not. ok this is what i am trying to do:

1) Add a document
2) get the same document out to print out
3) delete the same document
4) go back to step one.

This is a test case to test out the functionality of my application building on top of tamino.
The problem that i face is during the second iteration when after 4 goes back to 1,2,3 part 3 gets stuck in a delete operation when executing using the java tamino API. for the delete operation, i am using a x-query to perform the delete thru the TXMLObjectAccessor. I have verified that the first iteration is successful and it is always the second iteration that is stuck. in my code, prior to delete the document, i was reading it, so not too sure if the deleting operation is waiting for the read operation to release the lock( IF this is happening). if that is the case, then how did the first iteration manage to pass? some of the other stuff that i did to prevent the delete operation from getting stuck is to close the reading TXMLObjectIterator using the close() methods and nulling the iterator. Another thing i did was to create a new TXMLObjectAccessor to delete the object. but none of these worked. I have even tried to check the state of the lock mode and the lockwaitmode by retrieve the getLockMode(), getLockwaitMode() of the TXMLObjectAccessor but both of them return null. The most puzzling thing is that if the code is not correct, then why is the first iteration successful but not the second? by the way, the reading and deleting operations are within a transaction.By right, despite the number of iterations, each iteration should be successful becos they are supposed to be independent of each other but it doesnt seem to be the case here.

Am i barking up the wrong tree here? or is there something i didnt do?
Anyone, please help. Thanks

Hi,
Can you please post your code to the forum? If the entire code is too large, can you cut it down to the minimum that still shows the problem?

Many thanks.

//ADDING A DOCUMENT

//…getting connection
Element rootElement = new Element(“object”);
Element nameElement = new Element(“name”);
nameElement.setText(name);
Element addressElement = new Element(“address”);
addressElement.setText(“timbuktu”);
Element postalElement = new Element(“postal”);
postalElement.setText(“122345”);
Element miscElement = new Element(“misc”);
miscElement.setText(misc);

rootElement.addContent(nameElement);
rootElement.addContent(addressElement);
rootElement.addContent(postalElement);
rootElement.addContent(miscElement);

Document document = new Document(rootElement);
xmlObject = TXMLObject.newInstance(document);

accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), TJDOMObjectModel.getInstance());

try {

transaction = conn.useLocalTransactionMode();

response = accessor.insert(xmlObject);

nonxmlaccessor = conn.newNonXMLObjectAccessor(TAccessLocation.newInstance(collection));
TNonXMLObject nonXmlObject = TNonXMLObject.newInstance(data, null, “house”, housename, mime);
response = nonxmlaccessor.insert(nonXmlObject);

try {
transaction.commit();
}
catch (TTransactionException tTxEx) {
tTxEx.printStackTrace();
throw new DAOException (tTxEx);
}

/* code snippet that does the DELETING

deleting the document called object, which has a related document called house. The 2 documents are linked by postal in object

*/
String selectObjectXQuery = “input()/object[path="” + path + “" and name="” + name + “" and address="timbuktu"]/postal”;
String deleteObjectXQuery = “/object[path="” + path + “" and name="” + name + “"] “;

conn = (TConnection) dbConnPoolMgr.getConnection(dataSource);

String postal = null;
try {
transaction = conn.useLocalTransactionMode();
accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), TJDOMObjectModel.getInstance());
nonXmlAccessor=conn.newNonXMLObjectAccessor(TAccessLocation.newInstance(collection));

//this is the delete statement that gets stuck after the second iteration
response = accessor.xquery(TXQuery.newInstance(selectObjectXQuery));

iterator = response.getXMLObjectIterator();
if (iterator.hasNext()) {

postal = ( (Element) iterator.next().getElement()).getText();
}
//------this is the part that i was talking about in the post-------------------
iterator.close();
iterator=null;
accessor.invalidate();
accessor=null;
//------------------------------------------------------------------------------

//getting another accessor for the nonxml data
accessor1 = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), TJDOMObjectModel.getInstance());
response = accessor1.delete(TQuery.newInstance(deleteObjectXQuery));
String deletehouseXQuery = “/house[@docname="” + postal + “"]”;
TNonXMLObject house = TNonXMLObject.newInstance(new StringReader(””), null, “house”, postal, null);

response = nonXmlAccessor.delete(house);

try {
transaction.commit();
}
catch (TTransactionException tTxEx) {
tTxEx.printStackTrace();
}

}
catch (Exception ex) {
ex.printStackTrace();
try {
transaction.rollback();
}
catch (TTransactionException tTxEx) {
tTxEx.printStackTrace();
throw new DAOException(tTxEx);
}

throw new DAOException(ex);
}
finally {
if(iterator!=null)
{
try {
iterator.close();
iterator = null;
}
catch (TIteratorException tIterEx) {
tIterEx.printStackTrace();
}
}

if (conn != null) {
DbConnectionPoolManager.getInstance().freeConnection(conn, dataSource);
conn = null;
}
}

/* RETRIEVING the document - object

the document called object has a related document called house. The 2 documents are linked by postal in object

*/

String xquery = “input()/object[path="” + path + “" and name="” + name + “" and address="timbuktu" ]”;


conn = (TConnection) DbConnectionPoolManager.getInstance().getConnection(dataSource);
accessor = conn.newXMLObjectAccessor(TAccessLocation.newInstance(collection), TJDOMObjectModel.getInstance());

try {
response = accessor.xquery(TXQuery.newInstance(xquery));
iterator = response.getXMLObjectIterator();

if (iterator.hasNext()) {
Element rootElement = (Element) iterator.next().getElement();

String houseQuery = “/house[@docname="” + rootElement.getChildText(“postal”) + “"]”;

//getting the non xml data
nonxmlaccessor = conn.newNonXMLObjectAccessor(TAccessLocation.newInstance(collection));

TNonXMLObject house = TNonXMLObject.newInstance(new StringReader(“”), null, “house”, rootElement.getChildText(“postal”), null);
house.setDocname(rootElement.getChildText(“postal”));
ByteArrayOutputStream data = new ByteArrayOutputStream();
nonxmlaccessor.retrieve(house);
house.writeTo(data);
object = new Object(rootElement.getChildText(“path”), rootElement.getChildText(“name”), rootElement.getChildText(“address”), data.toByteArray(), key,rootElement.getChildText(“misc”)));
return folder;
}

Apologies for the late response, have been away on very busy business trip, just came back a day ago. Hope the code helps to understand the problem better. Thanks in advance!!!