spring-data

Spring data internationalization best practice

有些话、适合烂在心里 提交于 2021-02-05 20:07:04
问题 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

`Type cannot be null` exception when trying to run out Stored Procedure using Spring Data JPA

风格不统一 提交于 2021-02-05 09:40:52
问题 I am trying to invoke a Stored Procedure whose signature looks like the following: CREATE OR REPLACE PROCEDURE FIND_FIRST_BOOKMARK_GT(bookmark IN NUMBER, cur OUT SYS_REFCURSOR) I am using Spring-Data JPA and have tried a number of different variants, but all of them follow more or less the following pattern. My entity model is decorated as follows: @NamedStoredProcedureQuery(name = "Response.findFirstBookmarkGreaterThan", procedureName = "FIND_FIRST_BOOKMARK_GT", resultClasses = Response

Hibernate audit log of fields' change

若如初见. 提交于 2021-02-04 18:36:46
问题 How can I log the changes of the entity into log files? Consider I have Person like this. import org.hibernate.envers.Audited; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.GeneratedValue; import javax.persistence.Column; @Entity @Audited public class Person { @Id @GeneratedValue private int id; private String name; private String surname; // add getters, setters, constructors, equals and hashCode here } and a code of changing existing Person Person p1

@PreUpdate doesn't save parent object when it's updated

前提是你 提交于 2021-02-04 14:10:19
问题 I have two entities with relation one to many. Parent can have several Child entity instances. I added a field to the parent that stores the date of children modifications( childrenLastModifiedDate ). To maintain that, I added method: @PrePersist @PreUpdate @PreRemove private void handle() { parent.setChildrenLastModifiedDate(now()); } Here is the problem. It's not always invoke when the child is saved. Locally(mac os), it works as expected, all three types of changes are tracked and saved to

@PreUpdate doesn't save parent object when it's updated

我们两清 提交于 2021-02-04 14:08:50
问题 I have two entities with relation one to many. Parent can have several Child entity instances. I added a field to the parent that stores the date of children modifications( childrenLastModifiedDate ). To maintain that, I added method: @PrePersist @PreUpdate @PreRemove private void handle() { parent.setChildrenLastModifiedDate(now()); } Here is the problem. It's not always invoke when the child is saved. Locally(mac os), it works as expected, all three types of changes are tracked and saved to

@PreUpdate doesn't save parent object when it's updated

风格不统一 提交于 2021-02-04 14:08:47
问题 I have two entities with relation one to many. Parent can have several Child entity instances. I added a field to the parent that stores the date of children modifications( childrenLastModifiedDate ). To maintain that, I added method: @PrePersist @PreUpdate @PreRemove private void handle() { parent.setChildrenLastModifiedDate(now()); } Here is the problem. It's not always invoke when the child is saved. Locally(mac os), it works as expected, all three types of changes are tracked and saved to

@PreUpdate doesn't save parent object when it's updated

[亡魂溺海] 提交于 2021-02-04 14:07:57
问题 I have two entities with relation one to many. Parent can have several Child entity instances. I added a field to the parent that stores the date of children modifications( childrenLastModifiedDate ). To maintain that, I added method: @PrePersist @PreUpdate @PreRemove private void handle() { parent.setChildrenLastModifiedDate(now()); } Here is the problem. It's not always invoke when the child is saved. Locally(mac os), it works as expected, all three types of changes are tracked and saved to

Spring data - Refresh entity after “manual” backend query update [duplicate]

◇◆丶佛笑我妖孽 提交于 2021-02-04 13:34:28
问题 This question already has answers here : Spring Data JPA Update @Query not updating? (5 answers) Closed 10 months ago . let's suppose to have this situation: We have spring data configured in the standard way, there is a Respository object, an Entity object and all works well. Now for some complex motivations I have to use directly EntityManager (or JdbcTemplate , whatever is at a lower level than spring data) to update the table associated to my Entity , with a native sql query . So I'm not

How to log the queries executed by Spring Data MongoDB?

孤街醉人 提交于 2021-02-04 05:42:09
问题 Is there a way to find the query that was run against the database in spring data mongodb? I know this is possible in case of JPA. So was just wondering if there was something similar in Spring data MongoDB? 回答1: The easiest way is to set the log level to DEBUG for org.springframework.data.mongodb . 回答2: logging: level: org.springframework.data.mongodb.core.MongoTemplate: DEBUG To clarify Oliver's answer add that to the application.yml file or properties file. 来源: https://stackoverflow.com

How to log the queries executed by Spring Data MongoDB?

拈花ヽ惹草 提交于 2021-02-04 05:41:30
问题 Is there a way to find the query that was run against the database in spring data mongodb? I know this is possible in case of JPA. So was just wondering if there was something similar in Spring data MongoDB? 回答1: The easiest way is to set the log level to DEBUG for org.springframework.data.mongodb . 回答2: logging: level: org.springframework.data.mongodb.core.MongoTemplate: DEBUG To clarify Oliver's answer add that to the application.yml file or properties file. 来源: https://stackoverflow.com