Persistence Introduction | Persistence API Overview | Persistence Example
With MI 2.5 SP9 a new persistence API has been released. The changes improve the reliability and performance of the persistence API. The major changes are:
The migration is pretty straight forward. It affects mainly the entities and the the setup of the persistence manager.
The new PersistableEntity has to keep the PersistenceContainer
(formerly the PeristedObject) the lifetime of the entity. The attributes are
set on the PersistenceContainer and not on the Entity
anymore. The PersitableEntity has no more setInstance()
and getInstance()
method to implement.
Coding example
that shows the differences between PersistableEntity and Entity.
The PackagePersistenceMaster has to implement the PackageEntityFactory.
The definition of the descriptor runtime stays the same. The createEntity()
method now gets a PersistenceContainer.
Coding example that shows the changes for the PackagePersistenceMaster.
Ther persistence manager, like the transaction manager, comes from the PersistenceRuntime
with method getPersistenceMaster()
. The persistence manager allows
transactions (read and write) only when transactions are enabled with the methode
beginTransaction(boolean wait)
.
Coding example that shows the changes to set up the persistence runtime.
A persistence manager can be used until the data is finally persisted with
the commit()
method or rejected with the rollback()
method. After that a new persistence manager has to used.
Example:
public static void commit() { try { perManager.commit(); } catch (PersistenceException e) { System.out.println("Data can not be stored"); e.printStackTrace(); } try { // after commit a new persistence manager has to be set up perManager = persistence.getPersistenceManager(VisibilityType.SEPARATED); perManager.registerEntityFactory(master); perManager.beginTransaction(true); } catch (PersistenceException e1) { System.out.println("Persistence Manager cannot be started"); e1.printStackTrace(); } }