Issue
I have a one to one relationship like this:
@Entity
public class Modification {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="modification_id")
Long id;
@Column(name="second_line", length=1000)
String firstLine;
@OneToOne
@JoinColumn(name="tm_satus")
StatusOrder tmStatus;
// Constructors getters and setters
}
@Entity
public class StatusOrder {
@Id
@Column(name="status")
int status;
@Column(name="status_order")
int order;
// Constructors getters and setters
}
So every Modification
has a StatusOrder
.
Now I want to perform a query where I select from Modification
table ordered by order
field in StatusOrder
.
Is there a way to have a method in my repository like:
Page<Modification> findAllOrderByStatusOrder(Pageable pageable);
Solution
Try these,
@Query("SELECT m FROM Modiciation m ORDER BY m.tmStatus.order DESC")
Page<Modification> findAllOrderByStatusOrder(Pageable pageable);
or (I don't know if this'll work.)
Page<Modification> findAllOrderBytmStatus_orderDesc(Pageable pageable);
Answered By - Candoğuş Yılmaz
Answer Checked By - Dawn Plyler (JavaFixing Volunteer)