spring-data

How to cache results of a Spring Data JPA query method without using query cache?

南笙酒味 提交于 2020-01-10 06:44:26
问题 I have a Spring Boot app with Spring Data JPA (hibernate backend) repository classes. I've added a couple custom finder methods, some with specific @Query annotation to tell it how to get the data. I have already set up EhCache for the hibernate 2nd level cache, but so far, the only way I can get these results caching is to enable the hibernate query cache. I'd prefer to define a specific cache and store the actual domain objects there just as if it were a normal finder. Below is my repo code

Springboot :BeanDefinitionStoreException: Failed to parse configuration class

末鹿安然 提交于 2020-01-09 19:30:53
问题 I am trying to execute my springboot application by running the jar created with maven and getting below exception which is not getting resolved after so many attempts.Any help or pointers would be appreciated. Thanks in advance. Please find below exception trace. 2016-01-28 11:35:42.034 INFO 3732 --- [ main] Application : Starting Application on DFWLW72RTG262 with PID 3732 (C:\project\RestSpringBoot\target\springboot-0.0 .1-SNAPSHOT.jar started by vaigupta in C:\project\RestSpringBoot\target

Spring Data Rest 2.0.0.RELEASE Breaks Code Working Previously With RC1

邮差的信 提交于 2020-01-09 11:23:25
问题 I have a project which is utllizing Spring Data Rest. I originally had version 2.0.0.BUILD-SNAPSHOT in my pom.xml, but during my last update the code broke and began throwing the following IllegalStateException when accessing most endpoints: java.lang.IllegalStateException: No suitable resolver for argument [0] [type=org.springframework.http.converter.HttpMessageNotReadableException] HandlerMethod details: Controller [org.springframework.data.rest.webmvc.RepositoryEntityController] Method

Spring multiple Data Source configuration - Auto Fail over mechanism

这一生的挚爱 提交于 2020-01-07 02:53:04
问题 I would like to know if Spring offers any support for Auto Fail over of Data Sources? For example, if the primary data source is down, connect to secondary. Any suggestions to effectively configure auto fail over of Data sources is greatly appreciated. Thanks. 回答1: The Primary/DR setup for DB should be managed at DB level. Its not right to switch that in code. But to answer your question "can connect to 2 Data sources in Spring". Yes you can easier if you are using Spring-boot. Few details

Spring DataJPA custom query issue:

99封情书 提交于 2020-01-06 19:35:34
问题 I have a setup with JPA (hibernate + postgresql) and MongoDB: <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-mongodb</artifactId> <version>1.0.3.RELEASE</version> </dependency> <dependency> <groupId>org.springframework.data</groupId> <artifactId>spring-data-jpa</artifactId> <version>1.1.0.RELEASE</version> </dependency> My Repository Interface is: @Repository public interface JpaModelRepository extends JpaRepository<ModelEntity, Integer> { public ModelEntity

JPA + Spring Data - Can't get or delete persisted objects

为君一笑 提交于 2020-01-06 14:17:38
问题 I have a complex class hierarchy that looks like the following: @MappedSuperclass @Inheritance(strategy = InheritanceType.TABLE_PER_CLASS) public abstract class Person { protected String ssn; protected int age; @Id public int getSsn() { return ssn; } @Column public int getAge() { return age; } // Setter omitted } @MappedSuperclass @IdClass(EmployeeKey.class) public abstract class Employee extends Person { protected String badgeNumber; @Id public String getBadgeNumber() { return badgeNumber; }

IndexQueryBuilder method inside entity class results in “failed to index the document [id: 1]”

孤街浪徒 提交于 2020-01-06 11:09:11
问题 I got this error: org.springframework.data.elasticsearch.ElasticsearchException: failed to index the document [id: 1] at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.prepareIndex(ElasticsearchTemplate.java:1028) at org.springframework.data.elasticsearch.core.ElasticsearchTemplate.index(ElasticsearchTemplate.java:525) ... Every time that I put inside my entity Book class a getIndexQuery method. So it look like this: @Getter @Setter @NoArgsConstructor @AllArgsConstructor

Storing entire object as json in Spring Data

非 Y 不嫁゛ 提交于 2020-01-06 06:50:56
问题 I have the following domain object: @Data @Entity public class Person { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Long id; private String first; private String last; private Integer age; private String json; } and a PersonRepository extends Repository<Person, Long> . What I would like is to store in a table that looks like this: CREATE TABLE IF NOT EXISTS person ( id SERIAL NOT NULL PRIMARY KEY, json JSONB NOT NULL ); Is there a way to override the way Spring Data reads

Spring Data MongoRepository save causing Duplicate Key error

若如初见. 提交于 2020-01-06 06:49:09
问题 Here is the Entity: @Document @Data public class ApplicationUser { private String name; @Indexed(unique = true) private String email; private String organization = null; // other fields } I fetch this user using their email and then change their name. I use the autowired instance of ApplicationUserRepository. ApplicationUser applicationUser = applicationUserRepository.findByEmail("abc@gmail.com"); applicationUser.setName("John Doe 2"); Then I try to update this entity again in the database:

@CreatedDate annotated field is not written on Insert, @LastModifiedDate is

為{幸葍}努か 提交于 2020-01-06 06:36:14
问题 I created the following Entity and test it using h2: @Getter public class Topic { @Id private long id; private final Title title; @CreatedDate private LocalDateTime createdAt; @LastModifiedDate private LocalDateTime lastModified; // ... } The TopicRepository is an empty interface. The following test fails with the error that createdAt is null: @RunWith(SpringRunner.class) @SpringBootTest public class BasicRepositoryTests { @Autowired TopicRepository topicRepository; @Test public void