jpa

Spring Data JPA - query with the date minus 2 days not working

大憨熊 提交于 2021-02-07 09:30:43
问题 I have this query that updates some prices higher that 2 days ago, but does not work @Transactional @Modifying @Query("update HotelDailyPrice hdp set hdp.price = (select avg (hp.price) " + "from HotelPrice hp where hp.id = ?1 and hp.updateDate > CURRENT_DATE - 2), hdp.day = ?2 ") void updateDailyAveragePrice (Hotel hotel, String dayDate); 回答1: Actually, JPA doesn't support time periods operations because not all databases support it. So you have following options: Calculate date

Spring Data JPA - query with the date minus 2 days not working

南楼画角 提交于 2021-02-07 09:30:41
问题 I have this query that updates some prices higher that 2 days ago, but does not work @Transactional @Modifying @Query("update HotelDailyPrice hdp set hdp.price = (select avg (hp.price) " + "from HotelPrice hp where hp.id = ?1 and hp.updateDate > CURRENT_DATE - 2), hdp.day = ?2 ") void updateDailyAveragePrice (Hotel hotel, String dayDate); 回答1: Actually, JPA doesn't support time periods operations because not all databases support it. So you have following options: Calculate date

How to configure package level @TypeDefs with Spring Hibernate

谁说胖子不能爱 提交于 2021-02-07 06:52:30
问题 I need to configure @TypeDefs for use custom @Type on package level. When I configured it following manner I am getting ClassNotFoundException. But when I put @TypeDefs on the class level it is working fine. I have found similar kind of stackoverflow post but I haven't any idea to how to configure <resource package="com.foo.bar.thepackage"/> entry with my application-context.xml file. According some post (as bellow), noted this a Spring related bug I believe this is due to a bug in Spring,

Can't autowire repository from an external Jar into Spring Boot App

大憨熊 提交于 2021-02-07 06:52:17
问题 I have packaged my entire entities of the application and the repository interfaces into one jar. The repositories are written with @Repository annotation: @Repository public interface InternalUserRepository extends JpaRepository<InternalUser, Long>{ } I have included this jar file inside my spring boot application and trying to autowire the interface like this from a controller: @RestController public class AuthenticationController { @Autowired AuthenticationService authenticationService;

Identify constraint name that trigger DataIntegrityViolationException

依然范特西╮ 提交于 2021-02-07 04:01:50
问题 I am stuck with a issue of identify which constraint triggers DataIntegrityViolationException. I have two unique constraints: username and email but I have no luck trying to figure it out. I have tried to get the root cause exception but I got this message Unique index or primary key violation: "UK_6DOTKOTT2KJSP8VW4D0M25FB7_INDEX_4 ON PUBLIC.USERS(EMAIL) VALUES ('copeland@yahoo.com', 21)"; SQL statement: insert into users (id, created_at, updated_at, country, email, last_name, name, password,

Identify constraint name that trigger DataIntegrityViolationException

前提是你 提交于 2021-02-07 03:59:37
问题 I am stuck with a issue of identify which constraint triggers DataIntegrityViolationException. I have two unique constraints: username and email but I have no luck trying to figure it out. I have tried to get the root cause exception but I got this message Unique index or primary key violation: "UK_6DOTKOTT2KJSP8VW4D0M25FB7_INDEX_4 ON PUBLIC.USERS(EMAIL) VALUES ('copeland@yahoo.com', 21)"; SQL statement: insert into users (id, created_at, updated_at, country, email, last_name, name, password,

Identify constraint name that trigger DataIntegrityViolationException

坚强是说给别人听的谎言 提交于 2021-02-07 03:58:03
问题 I am stuck with a issue of identify which constraint triggers DataIntegrityViolationException. I have two unique constraints: username and email but I have no luck trying to figure it out. I have tried to get the root cause exception but I got this message Unique index or primary key violation: "UK_6DOTKOTT2KJSP8VW4D0M25FB7_INDEX_4 ON PUBLIC.USERS(EMAIL) VALUES ('copeland@yahoo.com', 21)"; SQL statement: insert into users (id, created_at, updated_at, country, email, last_name, name, password,

How to sort by querydsl alias

一笑奈何 提交于 2021-02-07 03:53:29
问题 Is there a way to sort repository query results by querydsl alias? So far I've managed to filter, but sorting results with an error: org.springframework.data.mapping.PropertyReferenceException: No property username found for type User! request: GET /users?size=1&sort=username,desc my rest controller method: @GetMapping("/users") public ListResult<User> getUsersInGroup( @ApiIgnore @QuerydslPredicate(root = User.class) Predicate predicate, Pageable pageable) { Page<User> usersInGroup =

How to sort by querydsl alias

主宰稳场 提交于 2021-02-07 03:51:40
问题 Is there a way to sort repository query results by querydsl alias? So far I've managed to filter, but sorting results with an error: org.springframework.data.mapping.PropertyReferenceException: No property username found for type User! request: GET /users?size=1&sort=username,desc my rest controller method: @GetMapping("/users") public ListResult<User> getUsersInGroup( @ApiIgnore @QuerydslPredicate(root = User.class) Predicate predicate, Pageable pageable) { Page<User> usersInGroup =

How to sort by querydsl alias

与世无争的帅哥 提交于 2021-02-07 03:51:18
问题 Is there a way to sort repository query results by querydsl alias? So far I've managed to filter, but sorting results with an error: org.springframework.data.mapping.PropertyReferenceException: No property username found for type User! request: GET /users?size=1&sort=username,desc my rest controller method: @GetMapping("/users") public ListResult<User> getUsersInGroup( @ApiIgnore @QuerydslPredicate(root = User.class) Predicate predicate, Pageable pageable) { Page<User> usersInGroup =