Here is an example of accessing Data with Spring JPA: http://spring.io/guides/gs/accessing-data-jpa/
Where are any persistence units and/or persistence.xml files there?
Related
I hope to achieve auditing of my tables using #Audited annotation of the Hibernate Envers project while I'm using Spring Data R2DBC or plain R2DBC to insert data into my tables.
Is this even feasible. I am not able to tell if Spring Data R2DBC uses hibernate at all.
I tried adding the #Audited annotation to my entity class to no avail.
this.fnclInfoRepository.save(itfnclinfo).subscribe();
#Data
#Builder
#Audited
public class Itfnclinfo implements Persistable<String> {
#Id
private String fnclInfoId;
..
}
I was expecting a new table created by hibernate with the suffix _AUD that holds the copy of all inserted data
I realize that Spring Data JPA is an abstraction over Hibernate and therefore Spring Data R2DBC is not a JPA provider abstraction and therefore not related to Hibernate. I'll have to come up with another way for auditing.
Spring data envers only works with traditional Spring Data JPA.
In a Spring Boot project, you can customize your AuditEvent and AuditEventRepository and setup the change log manually.
Check the Spring Boot docs - Auditing.
It maybe need more extra work, the good part is the auditevent is integrated with Spring Boot Actuator, you can track the auditevents by Actuator urls.
What is the main difference between Java Persistence API(JPA) and the Java Transaction API(JTA). I read these two terms in Java EE 7 .
JPA is an object-relational mapping tool that allows mapping between entity objects which are classes with their corresponding tables and their attributes in the database. Whereas JTA is a tool that allows you to make multiple transactions in multiple schema.
I really like the simplicity of spring data repository, however need to use hibernate as persistence provider for consistency and few other factors. (I am using mongodb but not using mongo template). Few things I noticed --
The HibernateJpaVendorAdapter uses "org.springframework.orm.jpa.vendor.SpringHibernateEjbPersistenceProvider"
The provider configured with the persistence unit ( ""org.hibernate.ogm.jpa.HibernateOgmPersistence" ) is not considered, while constructing the EntityManagerFactory through a "org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean" bean.
If there are multiple persistence units configured for the project there is no apparent way to associate a persistence unit for a repository.
Questions:
Is there a way to use the configured persistence provider , instead of the default one ? The default provider is not working with mongodb.
Is there a way to associate a repository with a specific persistence unit ?
A partial solution was to
implement
org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter and
return an instance of
org.hibernate.ogm.jpa.HibernateOgmPersistence in
getPersistenceProvider() method
Source the jpaVendorAdapter property for entityManagerFactory
bean in spring config
However it still doesn't work good wherever there is reference to Pageable. Some design change can circumvent the issue.
We are migrating from a Spring Data MongoDB repository to a Spring Data JPA repository. We were using the AbstractMongoEventListener to capture onBeforeConvert and onAfterLoad events to enhance the data objects before returning them from our Service layer.
I cannot find similar EventListeners in Spring Data JPA. Are there hooks in Spring Data JPA that I can use to do the same thing? It would be great if I can avoid modifying our service layer to make this change from MongoDB to JPA.
Thanks!
The #PrePersist annotation is exactly what I was looking for.
I have two persistence units with the same name, one in src/main/resources, another in src/test/resources. However, there is some information which is the same between them: list of entity classes, some (not all) properties, etc. How can I avoid duplicating it? If the answer depends on JPA implementation, I am interested in both OpenJPA and EclipseLink.
You can pass persistence unit properties at runtime in Persistence.createEntityManagerFactory(Map).
If they are separate persistence units they should have different names...