spring-data-jpa

ManyToMany relationship leads to StackOverFlow error

China☆狼群 提交于 2021-02-05 07:45:07
问题 I have an entity called User which has set of roles. I also have a Role entity which has set of users.( This is just a practice application for learning purposes.) public class User { private String firstName; private String lastName; @ManyToMany @JoinTable(name="user_role", joinColumns={@JoinColumn(name="user_id")}, inverseJoinColumns={@JoinColumn(name="role_id")}) private Set<Role> roles; //getters setters } public class Role { private String name; @ManyToMany(mappedBy="roles") private Set

How can I add columns dynamically to a Spring Data JPA @Query

拜拜、爱过 提交于 2021-02-05 07:28:25
问题 Consider the following method on a Spring Data JPA interface: @Query("select distinct :columnName from Item i") List<Item> findByName(@Param("columnName") String columnName); I would like to use such a method for performing queries dynamically using different column names on the same entity. How can this be done? 回答1: You can't. You'll have to implement such a method by yourself. And you won't be able to use parameters: you'll have to use String concatenation or the criteria API. What you'll

How can I add columns dynamically to a Spring Data JPA @Query

前提是你 提交于 2021-02-05 07:28:05
问题 Consider the following method on a Spring Data JPA interface: @Query("select distinct :columnName from Item i") List<Item> findByName(@Param("columnName") String columnName); I would like to use such a method for performing queries dynamically using different column names on the same entity. How can this be done? 回答1: You can't. You'll have to implement such a method by yourself. And you won't be able to use parameters: you'll have to use String concatenation or the criteria API. What you'll

How to retrieve entity relationships after save?

一个人想着一个人 提交于 2021-02-05 03:24:27
问题 I'm developing a RESTful webservice with spring-data as its data access layer, backed by JPA/Hibernate. It is very common to have relationships between domain entities. For example, imagine an entity Product which has a Category entity. Now, when the client POST s a Product representation to a JAX-RS method. That method is annotated with @Transactional to wrap every repository operation in a transaction. Of course, the client only sends the id of an already existing Category , not the whole

How to retrieve entity relationships after save?

柔情痞子 提交于 2021-02-05 03:23:01
问题 I'm developing a RESTful webservice with spring-data as its data access layer, backed by JPA/Hibernate. It is very common to have relationships between domain entities. For example, imagine an entity Product which has a Category entity. Now, when the client POST s a Product representation to a JAX-RS method. That method is annotated with @Transactional to wrap every repository operation in a transaction. Of course, the client only sends the id of an already existing Category , not the whole

How to retrieve entity relationships after save?

感情迁移 提交于 2021-02-05 03:21:07
问题 I'm developing a RESTful webservice with spring-data as its data access layer, backed by JPA/Hibernate. It is very common to have relationships between domain entities. For example, imagine an entity Product which has a Category entity. Now, when the client POST s a Product representation to a JAX-RS method. That method is annotated with @Transactional to wrap every repository operation in a transaction. Of course, the client only sends the id of an already existing Category , not the whole

javax.persistence.TransactionRequiredException: no transaction is in progress - Spring Batch

末鹿安然 提交于 2021-02-04 21:00:21
问题 I am using Spring Boot & Batch example. In this example, I am reading data from XML and writing to MySQL database. Here is the source code: https://www.linkedin.com/pulse/spring-batch-read-xml-prateek-ashtikar/?published=t. while running this example, I am getting below error - javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:409) ~

Spring JPA Repository ony fetches id instead of full object when it's already in result

﹥>﹥吖頭↗ 提交于 2021-02-04 16:24:06
问题 In a SpringBoot rest application, I have two classes as follows: User.java and Message.java. Message has -from- field (User) and also -to- is of type (User). So I've made it like this: In User.java: @Entity @JsonIdentityInfo(generator=ObjectIdGenerators.PropertyGenerator.class, property="id") public class User { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; private String firstName; private String lastName; private String email; @JsonIgnore @OneToMany(mappedBy =

How to access AuditReaderFactory in spring boot application?

…衆ロ難τιáo~ 提交于 2021-02-04 15:41:45
问题 I am using spring boot and spring data jpa. I am also using hibernate envers and I need access to AuditReaderFactory so that I can write Audit Queries. Since, its a spring boot and spring data jpa, everything is auto configured. So when I do this, @Autowired AuditReaderFactory auditReaderFactory; It doesn't work. I get the following error. org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.hibernate.envers.AuditReaderFactory] found for dependency:

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