spring-data

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

Spring Data JPA with ssh tunnel to a remote MySQL server

有些话、适合烂在心里 提交于 2021-02-06 14:24:55
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh

Spring Data JPA with ssh tunnel to a remote MySQL server

╄→гoц情女王★ 提交于 2021-02-06 14:05:21
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh

Spring Data JPA with ssh tunnel to a remote MySQL server

独自空忆成欢 提交于 2021-02-06 14:04:53
问题 I'm using Spring Data JPA with Hibernate as persistence provider in conjunction with a remote MySQL5 Server for a job that periodically replicates a subset of internal data. The job (i.e. a quartz-scheduled java application) runs once per dai and needs approx. 30seconds to complete the synchronization). For safety reasons we don't want to open the remote server for direct connections from outside (i.e. other than localhost). I've seen examples with Jsch to programmatically set up an ssh

How to refer long query, written in external file, in Spring data jpa @Query

我是研究僧i 提交于 2021-02-06 11:05:10
问题 I want to write query (properties or yaml) in external file to load database. - This is long query and does not look good to eye when placed inside @Query("long query") in XXXRepository class. Is there way to write this query in an external file (properties, yaml, xml or json) and call that file in @Query() in spring data jpa? 回答1: You can use named queries, where the queries have to be defined in a file called META-INF/jpa-named-queries.properties . See the spring example: User

How to refer long query, written in external file, in Spring data jpa @Query

╄→尐↘猪︶ㄣ 提交于 2021-02-06 11:04:55
问题 I want to write query (properties or yaml) in external file to load database. - This is long query and does not look good to eye when placed inside @Query("long query") in XXXRepository class. Is there way to write this query in an external file (properties, yaml, xml or json) and call that file in @Query() in spring data jpa? 回答1: You can use named queries, where the queries have to be defined in a file called META-INF/jpa-named-queries.properties . See the spring example: User

Exclude a specific table from being created by hibernate?

﹥>﹥吖頭↗ 提交于 2021-02-06 09:51:30
问题 I have an @Entity which is mapped to a view, here is how it looks import org.hibernate.annotations.Immutable; import javax.persistence.*; @Table(name = "user_earning") @Entity @Immutable public class UserFlightEarning { @Id public Long userId; public Long flightId; @Column(name = "flight_seq") public Long flightSequence; } This works fine, I can retrieve records from the view using the dao. However I noticed in the logs that Hibernate is actually trying to create the table but failing because

Spring data internationalization best practice

 ̄綄美尐妖づ 提交于 2021-02-05 20:11:13
问题 I have a spring mvc project with spring data, jpa and hibernate. I have a multilanguage database. I designed my database and entity. I am looking for a best practice to query my tables by language. Do I have to write custom jpa query, or is there a generic way to query my tables. If I have a mistake on db or entity design, please warn me. Database: CREATE TABLE translation ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)); CREATE TABLE translation_text ( translation_id BIGINT

Spring data internationalization best practice

陌路散爱 提交于 2021-02-05 20:11:01
问题 I have a spring mvc project with spring data, jpa and hibernate. I have a multilanguage database. I designed my database and entity. I am looking for a best practice to query my tables by language. Do I have to write custom jpa query, or is there a generic way to query my tables. If I have a mistake on db or entity design, please warn me. Database: CREATE TABLE translation ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, PRIMARY KEY (id)); CREATE TABLE translation_text ( translation_id BIGINT