spring-data-jpa

JPA filtering entities from a mapped association

安稳与你 提交于 2021-01-29 21:22:03
问题 My friendships sql table has column friend_1, friend_2, status . I have the following mappings in my (snippet below) User class. Currently user.getInitiatedFriendships returns list of Friendships where value of column friend_1 is equal to ID of the user I'm calling this getter on. user.getInvitedToFriendships() returns Friendships where column friend_2 is equal to ID of this user. I want to know if it is possible to add something to this line @OneToMany(mappedBy = "invitingUser" +>some check

JPA filtering entities from a mapped association

 ̄綄美尐妖づ 提交于 2021-01-29 19:06:06
问题 My friendships sql table has column friend_1, friend_2, status . I have the following mappings in my (snippet below) User class. Currently user.getInitiatedFriendships returns list of Friendships where value of column friend_1 is equal to ID of the user I'm calling this getter on. user.getInvitedToFriendships() returns Friendships where column friend_2 is equal to ID of this user. I want to know if it is possible to add something to this line @OneToMany(mappedBy = "invitingUser" +>some check

spring data jpa findAll can be called on associated entity of OneToOne Mapping

只愿长相守 提交于 2021-01-29 17:36:19
问题 I have two entity classes as below and corresponding repository interface Entity 1 @Data @NoArgsConstructor @Entity @Table(name = "person_details") public class PersonDetails { @Id private String pid; @Column(name = "first_name") private String firstName; @Column(name = "last_name") private String lastName; @Column(name = "exist_flag") private String existFlag; @OneToOne(mappedBy = "personDetails", cascade = CascadeType.ALL) private AddressDetails addressDetails; } Entity 2 @Data

how to use JPA Native query and TypedParameterValue to perform count

笑着哭i 提交于 2021-01-29 14:20:14
问题 I have an Entity class and I want to count the number of elements that satisfy some conditions in a PostgreSQL database. The entity contains many columns but I just need a response that returns the count of the selected columns as pending, approved, notSubmitted, submitted, approved, notapproved, queried... In order to avoid type mismatch from PostgreSQL driver, I am using the TypedParameterValue method. However I am getting a null value as a response instead of the actual value that should

JPA repository property expression

蓝咒 提交于 2021-01-29 14:19:38
问题 In my Spring Boot application (based on JHipster 4) I am trying to use property expressions to filter my query by attributes of related entities as described in the Spring docs: https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.query-methods.query-property-expressions I want to get all Appointments, with a certain EmployeeAccount in their AppointmentSchedules but only receive an empty list. @Repository public interface AppointmentRepository extends JpaRepository

Spring Data JPA “The column name Id is not valid”

坚强是说给别人听的谎言 提交于 2021-01-29 13:59:42
问题 I am trying to execute a raw SQL query against a SQL Server db using a Springboot project. I have the follwing repository: public interface BatchRepository extends PagingAndSortingRepository<Transaction, String> { @Override @Query(value = "SELECT DISTINCT(T.BatchNumber), T.Operator FROM TABLE T", nativeQuery = true) Iterable<Transaction> findAll(); } My entity backing the query is: @Entity @Table(name = "TABLE") public class Transaction implements EntityId<String>, CreatedDateTime,

Spring Boot : Using JPA want to get the unique value from table

喜欢而已 提交于 2021-01-29 13:29:09
问题 I have a table CatID | CategoryName | scatID | subCategoryName 2 User 1 x 2 User 2 y 2 User 3 z 2 User 4 a 2 User 5 b I am able to get all the value in JSON formate using SpringBoot. My Requirement : I want to get the unique CategoryName attribute but in current scenario I am getting all User coming 5 times. I am looking for solution. Please any one can help to get over using Spring Boot JPA implementation. 回答1: You can use the Query annotation in your repository interface. For example, below

@Query annotation with custom Class Spring Boot Java [closed]

♀尐吖头ヾ 提交于 2021-01-29 12:23:30
问题 Closed. This question needs debugging details. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 2 years ago . Improve this question question for JPA-Users, is the following somehow possible? @Query(value = "SELECT * FROM Users u WHERE u.status = :sampleClass.status", nativeQuery = true) List<SampleClass> findBySampleClass(SampleClass sampleClass); Notice the way I am trying to access SampleClass in the @Query

Write Spring Specification with multiple inner join & other conditions

我怕爱的太早我们不能终老 提交于 2021-01-29 12:14:06
问题 I am working on a project Spring and Java, generated using JHipster. I encounter a problem with the following items of Spring: Specification, Criteria, and filtering a list of items. I have a functioning SQL query, than I want to "translate" as a Spring Specification. But, I don't find how to do it, as the query works on 3 tables, and has 2 conditions. Basically, the work concerns 3 tables: contract, transfer & entry. A contract can be inside one or several transfers, and a transfer contains

Return type of JPA Repository 'getOne(id)' Method

眉间皱痕 提交于 2021-01-29 11:09:53
问题 I have the following Spring boot service for an object of type Report - @Service public class ReportService { @Autowired private ReportRepository reportRepository; @Autowired private UserRepository userRepository; /*get all reports */ public List<Report> getAllReports(){ return reportRepository.findAll(); } /*get a single report */ public Report getReport(Long id){ return reportRepository.getOne(id); } //other similar methods.... } The problem arises while retrieving a single Report. If a