Posts

Showing posts with the label spring-data-jpa

How to update an object with another object value in JPQL using Spring JPA

Image
Clash Royale CLAN TAG #URR8PPP How to update an object with another object value in JPQL using Spring JPA I'm facing a problem in JPQL. I have two entities like below class Employee{ private Long id; private String name; private Department department; public void setId(Long id){ this.id = id; } public void setName(String name){ this.name = name; } public void setDepartment(Department department){ this.department = department } public Long getId(){ return this.id; } public String getName(){ return this.name; } public Department getDepartment(){ return this.department; } } and... class Department{ private Long id; private String name; public void setId(Long id){ this.id = id; } public void setName(String name){ this.name = name; } public Long getId(){ return id; } public String getName(){ return name; } } Now i need to update an Employee 's department. I have tried the query below. Employee ...

No qualifying bean of type Error in Junit test

Image
Clash Royale CLAN TAG #URR8PPP No qualifying bean of type Error in Junit test I am trying to connect two different data source using spring boot version 2.0.3. One is pointing to the MySQL and another is PostgreSQL. MySQL passed every test. But problem with the PostgreSQL. Here is the Entity class that should be mapped to PostgreSQL. @Entity @Table(name = "order") @Data @NoArgsConstructor @AllArgsConstructor public class Order { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String productName; } This is the configuration class for PostgreSQL. @Configuration @EnableJpaRepositories( basePackageClasses = Order.class, entityManagerFactoryRef = "orderEntityManager", transactionManagerRef = "orderTransactionManager" ) @PropertySource("classpath:application.properties") public class OrderConfig { @Autowired Environment env; @Bean public DataSource getDataSource() { DriverManagerDataSource dataSo...

java.lang.IllegalStateException: No primary constructor found for java.util.List

Image
Clash Royale CLAN TAG #URR8PPP java.lang.IllegalStateException: No primary constructor found for java.util.List My project based on spring boot,Thymeleaf,mysql,html and Jquery. I tried to post a List of EntSetCharges type data to the @controller ,but it is not succeed..it trows error like java.lang.IllegalStateException: No primary constructor found for java.util.List Previously i worked with this error org.springframework.expression.spel.SpelEvaluationException: EL1007E: Property or field 'chargesName' cannot be found on null Now i got another error in same page Here is my full code... <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="ISO-8859-1"> <title>Insert title here</title> <!-- bootstrap css lib --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> </head> <body> <!-- Bootstrap...

One to many table relationship

Image
Clash Royale CLAN TAG #URR8PPP One to many table relationship I want to implement one to many table relationship with JPA: Main table Merchants @Entity @Table public class Merchants { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) private int id; @Column private String name; @Column private String login; } Second table Terminals which holds merchant id @Entity @Table public class Terminals { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) private int id; @Column private int merchant_id; @Column private String mode; } I tried this code implementation: @Entity @Table public class Merchants { @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id", updatable = false, nullable = false) private int id; @Column private String name; @...

how to use SpringData findAll() between select when using an object as major condition?

Image
Clash Royale CLAN TAG #URR8PPP how to use SpringData findAll() between select when using an object as major condition? So there's a method in SpringData findAll(Pageable pageable,Condition condition) ; , usually I use it like findAll(pageable,myobject) . findAll(Pageable pageable,Condition condition) ; findAll(pageable,myobject) The question is when it comes to select some records between some certain field range ,like select out objects whose createDate are between A and B , how to use findAll() ? findAll() I tried findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b) ; findAllByCreateDateAfterAndCreateDateBefore(Pageable pageable,Date a,Date b) But here I can't put myObj as a condtion into the method , and it caused a lot trouble when some fields in the myObj are not sure if it would be used as a condition. 1 Answer 1 You can simply use JPA Specification to do t...