EntityManager

Top  Previous  Next

An EntityManager will be generated for you if you define the catalog and dataSourceName attributes in the root schema element. The EntityManager can be used to insert, update and delete domain objects into a relational database (the EntityManager assumes that those domain objects actually model the appropriate tables from the catalog). The following code snippet shows how to use the EntityManager in a transaction-oriented way.

 

 

    final EntityManager manager = ObjectFactory.getEntityManager();
        
    final EntityManagerTransaction transaction = manager.beginTransaction(90);
        
    transaction.insert(dept10);
    transaction.insert(dept11);
    transaction.insert(dept12);
    transaction.commit();
        
    manager.endTransaction(transaction);

 

 

Similarly, if you just wanted to insert the 3 domain objects you could use the convenience method on the EntityManager.

 

 

    ObjectFactory.getEntityManager().insert(90,dept10,dept11,dep12);