Easy Way to Save a Collection of POJO Java Objects

Easy Way to Save a Collection of POJO Java Objects

Consider a simple POJO class, like the one shown below:

Class Person{   long id;   String firstName;   String lastName;   ...}

Now, suppose you want to persist a collection of Person objects. You can do it using the following code:

EntityManagerFactory factory =    Persistence.createEntityManagerFactory("testSample");OpenJPAEntityManager em = (OpenJPAEntityManager)    factory.createEntityManager();em.getTransaction().begin();List perList = new ArrayList();perList.add(new Person(1,"firstname1","lastname1"));perList.add(new Person(1,"firstname1","lastname1"));em.persistAll(perList );em.getTransaction().commit();em.close();factory.close();
Share the Post:
data observability

Data Observability Explained

Data is the lifeblood of any successful business, as it is the driving force behind critical decision-making, insight generation, and strategic development. However, due to its intricate nature, ensuring the

Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular