Creating new objects

A method called sampleInsert() is used in the application to store objects in the database. In this method at first the initialised persistence manager factory creates a persistence manager:
public void sampleInsert() 
{
 PersistenceManager pm = pmf.getPersistenceManager();
...
}

Transactions

Signsoft intelliBO provides transaction control. Every writing database actions have to be run inside a transaction. You get an transaction object from the persistence manager:

Transaction tx = pm.currentTransaction();
tx.begin();
...
tx.commit();
All your database actions that belong together take place between the two calls tx.begin() and tx.commit() . The changes that you made are stored persistently in the database when the call tx.commit() works without an error. You can undo any changes by calling tx.rollback() as long as you have not called tx.commit() already.

Create a new Person object now:

Person p = new Person(); 
p.setLastName("Edwards");
p.setFirstName("James");
p.setPhone("01222-25652");

and make it persistent with:

pm.makePersistent(p);

At the end commit the transaction with tx.commit() and close the persistence manager with pm.close() .

A complete method to store two Person objects could look like this:

public void sampleInsert() 
{
 PersistenceManager pm = pmf.getPersistenceManager();

 Transaction tx = pm.currentTransaction();
 tx.begin();

 Person p = new Person();
 p.setLastName("Edwards");
 p.setFirstName("James");
 System.out.println("creating " + p);
 pm.makePersistent(p);

 p = new Person();
 p.setLastName("Smith");
 p.setFirstName("Jane");
 System.out.println("creating " + p);
 pm.makePersistent(p);

 tx.commit();
 
 pm.close();
}