I have a spring boot application with objectdb embedded database.
I am manually handling connection and transaction operations as described at https://www.objectdb.com/java/jpa/persistence/overview
Below is a sample code that I am using: (taken from objecdb documentation):
EntityManagerFactory emf = Persistence.createEntityManagerFactory("myDbFile.odb"); EntityManager em = emf.createEntityManager(); try { em.getTransaction().begin(); // Operations that modify the database should come here. em.getTransaction().commit(); } finally { if (em.getTransaction().isActive()) em.getTransaction().rollback(); }
It works but the code has become uggly since I had to use try catch finally blocks in order to properly close connections.
I want to refactore my application so that database operations are done in JpaRepositories or Dao classes with @Transactional methods (as described in https://spring.io/guides/gs/accessing-data-jpa/)
I had a research on the web but could not find any solution that works. Existing spring-objectdb questions are usually related to regular spring or previous objectdb versions (before to 2.6.3). I could not make them work.
What I am looking for is a very simple spring boot sample application with:
- spring-boot-starter-data-jpa
- Objectdb (embedded)
- Maven
- Uses annotation based configuration (no xml file)
- A dummy entity class (e.g: Customer(id,firstname) )
- A JpaRepository class or dao class with list() and @Transactional persist(Customer) methods
Thanks in advance..