spring-data-jpa

NullPointerException on QueryDSL where clause

有些话、适合烂在心里 提交于 2021-01-28 03:08:07
问题 Using Query DSL with hibernate (Spring Data JPA) to build a query like so if( bankId != null ){ query.where( coopMember.personId.bankAccountId.isNotNull().and( coopMember.personId.bankAccountId.bankBranch.bankId.eq(bankId)) ); } return query.fetch(); The logic here is simple: if there is a bank account associated with a person, filter the results by bank id. The BankAccount entity has a BankBranch which holds bankId integer value. A CoopMember entity may or may not have a BankAccount Problem

SpringBootTest is connecting to database

眉间皱痕 提交于 2021-01-28 02:43:38
问题 I have a test that is testing parts of a spring application. It is using SpringRunner and the annotaion @SpringBootTest so it is starting a full spring server. Problem is that the test is being executed by a server that does not have access to the database, so I am getting a lot of connection timeouts that is slowing down the test. The connection issues in itself isn't really a problem as the tests are mocking the calls to the database, and so they are not relying on the connection being

NullPointerException on QueryDSL where clause

纵然是瞬间 提交于 2021-01-28 00:30:22
问题 Using Query DSL with hibernate (Spring Data JPA) to build a query like so if( bankId != null ){ query.where( coopMember.personId.bankAccountId.isNotNull().and( coopMember.personId.bankAccountId.bankBranch.bankId.eq(bankId)) ); } return query.fetch(); The logic here is simple: if there is a bank account associated with a person, filter the results by bank id. The BankAccount entity has a BankBranch which holds bankId integer value. A CoopMember entity may or may not have a BankAccount Problem

Spring to Spring boot migration. Embedded Spring Data source

旧时模样 提交于 2021-01-27 23:20:37
问题 Currently, it has been used Spring Boot application with the custom Data source configuration like this one Before @SpringBootApplication(exclude={DataSourceAutoConfiguration.class, MongoAutoConfiguration.class}) public class SpringBootAppInitializer { public static void main(String[] args) { System.setProperty("java.awt.headless", "false"); SpringApplication.run(SpringBootAppInitializer.class); } } @Bean public BasicDataSource getDataSource() { BasicDataSource basicDataSource = new

Variables in Spring Data JPA native query

耗尽温柔 提交于 2021-01-27 20:40:25
问题 Using Spring Dat JPA, I need to query my database and return a range of OrderEntity s based on a startAmt and a endAmt of amounts. I'm not sure if I should map these two variables to entity OrderEntity , as fields in some type of separate class/entity/model, or simply declare them in my native query. Perhaps I should be using a service that implements EntityManager.createNativeQuery() ? Would like to do something like : @Repository public interface OrderRangeRepository extends JpaRepository

Does @PreUpdate always run when @PrePersist runs?

梦想的初衷 提交于 2021-01-27 20:23:16
问题 I have an Entity like below: @Entity public class Order { @Id private String orderId; @Temporal(TemporalType.TIMESTAMP) @Column(name = "created_at", nullable = false) private Date created; @Temporal(TemporalType.TIMESTAMP) @Column(name = "updated_at", nullable = false) private Date updated; @PrePersist protected void onCreate() { this.created = new Date(); this.updated = this.created; } @PreUpdate protected void onUpdate() { this.updated = new Date(); } } I have to find all the orders that

Spring-boot error using Apache Derby as embedded database

♀尐吖头ヾ 提交于 2021-01-27 19:58:55
问题 I am new to using spring boot. I am trying to create a REST API with apache derby as an embedded database but I get this error: "Error creating bean with name 'entityManagerFactory'". pom.xml : http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 <groupId>com.restapi</groupId> <artifactId>restApi</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>restApi</name> <description>Demo project for Rest API with spring boot</description> <parent> <groupId>org

How to use multiple schema's in one database by using JPA + Hibernate with Spring-boot?

别来无恙 提交于 2021-01-27 19:17:10
问题 I need it to access 2 different schema's in one database(MySQL). I wrote two config classes here: package twodb.webfi.config; import java.util.Properties; import javax.persistence.EntityManagerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration;

@OneToMany relationship does not save the primary key of the parent in the children tables

北慕城南 提交于 2021-01-27 19:11:11
问题 Let there be three JPA Entities. A Person and two one-to-many relations to it. When I'm trying to save the Person AD_P_ID and AC_P_ID foreign keys are always null. The expected value for these fields is the person Id. What am I doing wrong? Person.java: This contains one to Many relationships with Account and Address Entity classes: @Entity @Table(name = "A2C_PERSON") class Person implements Serializable { private long id; private List<Account> acs; private List<Address> ads; @OneToMany

When i am using it with db2 for pagination, my next page is giving error

橙三吉。 提交于 2021-01-27 14:38:26
问题 I am using spring data jpa with db2. My first set of record is coming. But when i do the next, it is giving me error. I guess it may be because of db2. When I use index 0 it is working fine. But when i use index 1 then it is giving data access exception. On second page I am getting below error my pageable object Pageable pageable = new PageRequest(2, 10, Direction.ASC, "messageId"), because of this 2(As it is mentioning that index should be 0), it is throwing the below error com.ibm.db2.jcc