Я хочу получить только отдельные записи таблицы User
из таблицы RideTransaction
.
До сих пор я попробовал следующий запрос
@Query("SELECT r FROM RideTransaction r WHERE r.user=?1 AND r.status='RIDING' OR r.status='OUTSTANDING' OR r.status='COMPLETED'")
List<RideTransaction> findRideHistoryOfUser(User user);
А еще есть
@Query("SELECT r FROM RideTransaction r WHERE r.user=?1 AND r.status='RIDING' OR r.status='OUTSTANDING'")
List<RideTransaction> findAllCurrentRidingOrOutstanding(User user);
, но когда я выполнил вышеуказанный код, я получаю все RideTransaction
записей вместо отдельных User
записей.
Таблица RideTransaction:
@Entity
public class RideTransaction {
@Id
@GenericGenerator(name = "ridetransection_id_generator", strategy = "com.greensaikil.entity.idgenerator.RideTransectionIdGenerator")
@GeneratedValue(generator = "ridetransection_id_generator")
private long id;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "USER", foreignKey = @ForeignKey(name = "FK_RideTransection_User"))
private User user;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "DROP_UP_STAND", foreignKey = @ForeignKey(name = "FK_RideTransection_Stand_DropUp"))
private Stand drop_up_stand;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "PICK_UP_STAND", foreignKey = @ForeignKey(name = "FK_Transection_Stand_PickUp"))
private Stand pick_up_stand;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "BICYCLE", foreignKey = @ForeignKey(name = "FK_Transection_Bicycle"))
private Bicycle bicycle;
private Date pick_up_time;
private Date drop_off_time;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "PICK_UP_LOCATION", foreignKey = @ForeignKey(name = "FK_RideTransection_Location_PickUp"))
private Location pick_up_location;
@OneToOne(cascade = { CascadeType.ALL })
@JoinColumn(name = "DROP_UP_LOCATION", foreignKey = @ForeignKey(name = "FK_RideTransection_Location_DropUp"))
private Location drop_off_location;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Payment> payments = new HashSet<Payment>();
private long booking_ride_time;
private BigDecimal total_payment;
private BigDecimal remaining_outstanding;
private BigDecimal discount;
private Date booking_time;
private long total_ride_time;
private long extra_ride_time;
private BigDecimal total_rental;
@Enumerated(EnumType.STRING)
private RideStatus status;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<Image> image;
@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
private Set<RideTracking> ride_tracking = new HashSet<RideTracking>();
//setters and getters
Таблица пользователей:
public class User {
@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@Column(columnDefinition = "BINARY(16)", name = "USERID")
private UUID id;
@Column(name = "USERNAME")
private String username;
@Column(name = "NAME")
@NotNull
private String name;
@Column(name = "USEREMAIL")
private String email;
@Column(name = "USERPHONE")
private Long phone;
//setters and getters
Места помогают мне с запросом получить только User
записей.