Following previous questions on the subject I'd like to share a simple working example of ObjectDB and Spring Boot.
The code of the example can be found here:
https://github.com/kirshamir/spring-data-jpa-objectdb
The example uses the automatic query generation performed by Spring and it works very nicely with objectdb:
public interface PersonRepository
extends JpaRepository<Person, Long> {
List<Person> findAllByBirthDateBetween(Date d1, Date d2);
List<Person> findAllByGender(Person.Gender g);
List<Person> findAllByBirthDateBetweenAndGender(Date d1, Date d2, Person.Gender gender);
// the above are supported by spring data, see:
// https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#jpa.query-methods.query-creation
@Query("Select p from Person p WHERE MONTH(p.birthDate) = :month")
List<Person> findAllByBirthDateMonth(int month);
List<Person> findAllByBirthDateYear(int year);
@Query("Select p from Person p WHERE YEAR(p.birthDate) = :year")
}
In order to avoid the need to configure RDBMS in application.properties and/or in pom.xml I added the following beans:
@Bean @ConfigurationProperties("app.datasource")
public DataSource dataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name="entityManagerFactory")
public EntityManagerFactory getEntityManagerFactoryBean() {
return Persistence.createEntityManagerFactory("spring-data-jpa-test.odb");
}
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory emf) {
JpaTransactionManager txManager = new JpaTransactionManager();
txManager.setEntityManagerFactory(emf);
return txManager;
}