Some additional supplements of JDO MakePersistent

xiaoxiao2021-03-06  120

Public void makepersistent (java.lang.Object PC)

Parameters:

PC - a TRANSIENT INSTANCE OF A

Class That Implements

PersistenceCapable

This is a segment definition of MakePersistent in JDO-Javadoc, and a PC is an instanto instance object.

In fact, a Persistent New instance can also make MakePersistent, and a personistent dirty instance is not

Test code:

1. Persistent Persistent New object

PersistenceManager pm = PersistenceManagerSource.distinctPM (); Transaction t = pm.currentTransaction (); t.begin (); userDAO.setPoClass (User.class); try {user = (User) userDAO.getObjectById (pm, id); / / Get the Persistent New User Object Pm.makePersistent (user) from DAO; // Persistence operation, this operation is not wrong

PM.makeTransient (user);

} catch (daoException e) {if (t.isactive ()) T. Rollback (); // Todo auto-generated catch block E.PrintStackTrace ();} finally {ix (t.isactive ()) T.Commit ); If (pm! = Null) pm.close ();} return user;

2. Persistence Persistent Dirty object

PersistenceManager pm = PersistenceManagerSource.distinctPM (); Transaction t = pm.currentTransaction (); t.begin (); userDAO.setPoClass (User.class); try {user = (User) userDAO.getObjectById (pm, id); / / Get the Persistent New User object from Dao

User.setUsername ("jjyao"); pm.makepersistent (user); // persistent operation, this operation error

PM.makeTransient (user);

} catch (daoException e) {if (t.isactive ()) T. Rollback (); // Todo auto-generated catch block E.PrintStackTrace ();} finally {ix (t.isactive ()) T.Commit ); If (pm! = Null) pm.close ();} return user;

转载请注明原文地址:https://www.9cbs.com/read-98205.html

New Post(0)