spring-data-jpa

Use of @OneToMany or @ManyToMany targeting an unmapped class exception occuring

烈酒焚心 提交于 2021-02-11 15:36:10
问题 I am creating my first Spring-Boot-Starter-data-jpa project. I was following a tutorial on that and creating a separate application in same way. When I am starting my Spring Boot application , I am getting org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org

Use of @OneToMany or @ManyToMany targeting an unmapped class exception occuring

倾然丶 夕夏残阳落幕 提交于 2021-02-11 15:33:59
问题 I am creating my first Spring-Boot-Starter-data-jpa project. I was following a tutorial on that and creating a separate application in same way. When I am starting my Spring Boot application , I am getting org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org

Use of @OneToMany or @ManyToMany targeting an unmapped class exception occuring

可紊 提交于 2021-02-11 15:33:27
问题 I am creating my first Spring-Boot-Starter-data-jpa project. I was following a tutorial on that and creating a separate application in same way. When I am starting my Spring Boot application , I am getting org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is org

Spring Data/JPA: How do I save an item with multiple child collections?

半城伤御伤魂 提交于 2021-02-11 15:04:36
问题 I am struggling with understanding how to use Spring Data/JPA to interact with a database. I'm using the simple H2 database currently for testing purposes. I have a main item, Task , that in addition to fields, also has two collections of "child" data: TaskNote and StateChangeHistory . In my task service class, I have a @PostConstruct method to set up some dummy data and save it to the database so that I can retrieve and display it later. It appears that the Task is being saved, but none of

Compare LocalDate with LocalDateTime in HQL/JPQL

…衆ロ難τιáo~ 提交于 2021-02-11 14:53:24
问题 Is it possible to compare LocalDate with LocalDateTime in HQL/JPQL? This is my query of repository method in spring data which should return amount of orders per required dates. The field deliveryDateTime in Order entity has type LocalDateTime . I want to ignore time part and compare only date part. @Query("SELECT new OrderCountPerDate(DATE(o.deliveryDateTime), COUNT(o.id)) FROM Order o WHERE DATE(o.deliveryDateTime) IN :dates GROUP BY DATE(o.deliveryDateTime) ") List<LocalDate>

How to accept @OrderBy of JPA sort value as a dynamic parameter?

痴心易碎 提交于 2021-02-11 14:21:51
问题 I want to sort a nested collection property dynamically based on the query parameter sort. Suppose i have an entity A as class A{ @OneToMany(mappedBy="a") private Set<B> bset; } class B{ private LocalDate datefield; @ManyToOne private C c; } class C { private Double quantity; } I am calling repository of A with findAll(Specification specification,Pageable page) From UI, rest controller is called with sort param as below pattern url?page=0&size=10&sort=bset_datefield As it is a nested

PageRequest and OrderBy method name Issue

被刻印的时光 ゝ 提交于 2021-02-11 14:14:06
问题 in our Spring application we have a table that contains a lot of "Payment" record. Now we need a query that pages the results sorted from the one with the largest total to the smallest, we are facing an error because sometimes the same record is contained in two successive pages. We are creating a PageRequest passed to the repository. Here our implementation: Repository: public interface StagingPaymentEntityRepository extends JpaRepository<StagingPaymentEntity, Long> { Page

Test Spring batch with @JpaDataTest

∥☆過路亽.° 提交于 2021-02-11 12:32:33
问题 I'm using spring batch 4.0 and i'm trying to test my batch. I would use embedded database h2 with @JpaDataTest but it doesn't work. When i add this annotation i got error java.lang.IllegalStateException: Existing transaction detected in JobRepository. Please fix this and try again (e.g. remove @Transactional annotations from client). @Transaction(propagation=Propagation.NEW_REQUIRED) on the @Test dosen't work. I tried to copy every annotations from @JpaDataTest and remove @Transaction

Entity not returned from L1 cache

余生颓废 提交于 2021-02-11 07:19:45
问题 We are using Spring JPA in our project without any L2 cache. As per the docs, within a session, the related entities are returned from the L1 cache. To test this out, in application.yml I enabled the query generation spring.jpa.show-sql=true spring.jpa.properties.hibernate.format_sql=true In the implementation class, I added the following two lines of code. Employee emp1 = employeeRepository.getByEmployeeCode(empCode); Employee emp2 = employeeRepository.getByEmployeeCode(empCode); I was

Spring Data Projection loads additional Fields

故事扮演 提交于 2021-02-11 04:57:35
问题 I have a small issue. Let’s assume I have this Entity: import lombok.Data; import javax.persistence.*; import java.util.Set; @Data @Entity public class Person { enum SEX {F, M} @Id @GeneratedValue private Long id; @OrderBy @Enumerated(EnumType.STRING) @ElementCollection(fetch = FetchType.EAGER) private Set<SEX> sexes; private String firstName; private String lastName; } Because at some points I do not want to load the first and last name, I use Projections (https://docs.spring.io/spring-data