Hi All,
I have made one DAO-Impl class using GAE JDO. It does the find and save
operaions fine but when it comes to deleting an object it keeps giving an
error like this:
Caused by: java.lang.RuntimeException: javax.jdo.JDOUserException:
Transient-Transactional instances cant be deleted. Object id = {0}
NestedThrowables:
org.datanucleus.exceptions.NucleusUserException:
Transient-Transactional instances cant be deleted. Object id = {0}
at
com.gp.med.diag.dao.impl.DefaultDaoImpl.delete(DefaultDaoImpl.java:37)
at
com.gp.med.diag.bean.UserRequestBean.deleteSelectedUsers(UserRequestBean.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at
com.google.appengine.tools.development.agent.runtime.Runtime.invoke(Runtime.java:100)
at com.sun.el.parser.AstValue.invoke(AstValue.java:187)
at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:297)
at
com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:98)
at
javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
... 33 more
Below is my DefaultDaoImpl class:
package com.gp.med.diag.dao.impl;
import com.gp.med.diag.common.CommonUtility;
import com.gp.med.diag.dao.DefaultDao;
import java.io.Serializable;
import java.util.List;
import java.util.logging.Logger;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.jdo.Transaction;
public class DefaultDaoImpl<T, Key extends Serializable> implements
DefaultDao<T, Key> {
private Logger log = Logger.getLogger(this.getClass().getName());
/**
*/
private static final long serialVersionUID = -7434657287999140983L;
@Override
public void delete(T t) {
PersistenceManager pm = CommonUtility.get().getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// T t = findByKey(clazz, key);
log.finer("Deleting object:" + t);
pm.makeTransactional(t);
// pm.retrieve(t);
pm.deletePersistent(t);
tx.commit();
} catch (Exception e) {
tx.rollback();
throw new RuntimeException(e);
} finally {
pm.close();
}
}
@SuppressWarnings("unchecked")
@Override
public List<T> findAll(Class<T> clazz) {
PersistenceManager pm = CommonUtility.get().getPersistenceManager();
try {
Query query = pm.newQuery(clazz);
List<T> result = (List<T>) query.execute();
result.size();
pm.detachCopyAll(result);
return result;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
pm.close();
}
}
@Override
public T findByKey(Class<T> clazz, Key key) {
PersistenceManager pm = CommonUtility.get().getPersistenceManager();
try {
T t = (T) pm.getObjectById(clazz, key);
pm.detachCopy(t);
return t;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
pm.close();
}
}
@Override
public T save(T entity) {
PersistenceManager pm = CommonUtility.get().getPersistenceManager();
try {
return pm.makePersistent(entity);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
pm.close();
}
}
@Override
public void update(Class<T> clazz, Key key, T entity) {
PersistenceManager pm = CommonUtility.get().getPersistenceManager();
try {
// T t = findByKey(clazz, key);
pm.makePersistent(entity);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
pm.close();
}
}
}
When I was not calling the makeTransactional() method in the delete() method
I was getting an error like "Cannot delete a Transient instance".
Thanks for your help.
Regards,
Gurdev
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.