spring-data-jpa

Add Custom Method to JPARepository with Generics

Deadly 提交于 2021-02-08 09:16:37
问题 Assume I have a Entity called Product . I design a Repo as @Repository interface ProductRepository implements JPARepository<Product, Integer>{} This would inherit all the default methods such as save, findAll etc; Now I want to have one custom method, which is also a common method for other entities. I added another interface and implementation interface CustomRepository<T,ID>{ public void customMethod() } class CustomRepositoryImpl implements CustomRepository<T,ID>{ public void customMethod(

Spring JPA Datasource Crash Recovery and Dynamic Changes on runtime

徘徊边缘 提交于 2021-02-08 09:15:36
问题 Hi I use spring jpa and as I understand its working mechanism truely it created at once in a singleton way. Is it possible to change or recreate datasource on running environment.Scenario like this,Mypassword changed and if I wont stop application that time all my calls take exception.I have a mechanism to check password and change it dynamically and my others request get new password create new datasource and keep on working. And another question is I have multiple datasource,at the

Spring JPA Datasource Crash Recovery and Dynamic Changes on runtime

こ雲淡風輕ζ 提交于 2021-02-08 09:04:04
问题 Hi I use spring jpa and as I understand its working mechanism truely it created at once in a singleton way. Is it possible to change or recreate datasource on running environment.Scenario like this,Mypassword changed and if I wont stop application that time all my calls take exception.I have a mechanism to check password and change it dynamically and my others request get new password create new datasource and keep on working. And another question is I have multiple datasource,at the

Not exposing the path of entities that have a composite primary key to the front end when using the Springframework Page object

你离开我真会死。 提交于 2021-02-08 07:29:33
问题 I'm working on an API endpoint that returns a Springframework Page response. I want the front end to be able to sort the data but I can't expect the front end to know that the column they want to sort on is actually inside a composite primary key. In the example below (a simplified version of what I'm working on) you can see that the startDate column is inside a RouteEntityPk class, which is linked to the RouteEntity class with the @EmbeddedId annotation. To Sort on that column the front end

Polymorphic query in spring data

你。 提交于 2021-02-08 05:17:52
问题 I have one base abstract class. @Entity @Table(name = "P_FLD") @Inheritance(strategy = InheritanceType.JOINED) @DiscriminatorColumn(name = "FLD_DISCRIMINATOR", columnDefinition = "CHAR(3)") abstract public class AbstractPassbookField and some classes that extends it. For example: @Entity @DiscriminatorValue("F") @Table(name = "P_FLD_F") public class PassbookFileField extends AbstractPassbookField and i create repository for base entity public interface PassbookRepository extends

Can we build Spring Data JPA specification out of a composite key attribute

纵饮孤独 提交于 2021-02-07 18:12:29
问题 I am using Spring Data JPA specifications for generic queries to my entities. So far it has worked well. Now the problem happened when I try to use these on composite keys used via embeddedId annotation. So here I need to use a nested property to query which say if the object is Foo and I am trying to write a criteria over id. id1 for example. @Entity @Data public class Foo implements Serializable { private static final long serialVersionUID = 1L; /** The key. */ @EmbeddedId private FooKey id

spring jpa nested projection generating incorrect query

孤街浪徒 提交于 2021-02-07 13:39:29
问题 Lets consider these entities @Entity public class Room{ @Id private Integer id; private String number; private String floor; @ManyToOne private RoomType roomType; // Setters & Getters } @Entity public class RoomType{ @Id private Integer id; private String name; private String description; private Boolean enabled; // Setters & Getters } And also this interface for projection alongside repository class public interface RoomList{ public Number getId(); public String getNumber(); public RoomType

spring jpa nested projection generating incorrect query

删除回忆录丶 提交于 2021-02-07 13:36:47
问题 Lets consider these entities @Entity public class Room{ @Id private Integer id; private String number; private String floor; @ManyToOne private RoomType roomType; // Setters & Getters } @Entity public class RoomType{ @Id private Integer id; private String name; private String description; private Boolean enabled; // Setters & Getters } And also this interface for projection alongside repository class public interface RoomList{ public Number getId(); public String getNumber(); public RoomType

Spring Batch - How to prevent database commits with jobLauncherTestUtils

大兔子大兔子 提交于 2021-02-07 12:55:50
问题 I have Spring Batch job that writes to the database (it has a step with a JpaItemWriter ). I have an integration test such as follows: @RunWith(SpringRunner.class) @SpringBootTest @ActiveProfiles("integrationTest") public class LoadApplicationTests { @Autowired private Job job; @Autowired private JobRepository jobRepository; @Autowired private JobLauncher jobLauncher; private JobLauncherTestUtils jobLauncherTestUtils; @Before public void setUp() throws IOException, java.text.ParseException,

How to update ManyToMany with extra columns

感情迁移 提交于 2021-02-07 10:30:46
问题 I am trying to figure out how to resolve the issue which I am having now. I have three entities, Company, User and Affiliation. The Affiliation table is a link table for ManyToMany relationship between Company and User entities and has extra columns which I need to use. On company side I have: @JsonManagedReference @OneToMany(mappedBy = "company", cascade = CascadeType.ALL, orphanRemoval = true) private Set<Affiliation> affiliations = new HashSet<>(); On User side I have: