this is my first question in stackOverflow, if theres anything wrong or offend, pls let me know.
Im trying to join theses tables (or entity?) and retrieve the datas
My goal is to retreive the specific coulmns , like member.id, order_detail.total_amount
and send to the front instead of whole datas
@Entity
@Table(name = "member")
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int id;
private String email;
private String password;
@OneToMany(mappedBy = "member", cascade = CascadeType.ALL, orphanRemoval = true)
private List<Order_detail> orders;
public Member() {
}
public Member(String email, String password) {}
}
@Entity
@Table(name = "order_detail")
public class Order_detail {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer order_id;
private Date order_date;
private Integer total_amount;
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "id")
@JsonIgnore
private Member member;
public Order_detail() {}
public Order_detail(Integer order_id, Date order_date, Integer total_amount) {
this.order_id = order_id;
this.order_date = order_date;
this.total_amount = total_amount;
}
Currently I can retrieve all the datas by useing this query
@Repository
public interface MemberRepository extends JpaRepository<Member,Integer> {
@Query("SELECT m FROM Member m JOIN m.orders o WHERE m.id = :memberId")
List<Member> findMemberWithOrders(@Param("memberId") int memberId);
}
But when I try this one
@Repository
public interface MemberRepository extends JpaRepository<Member,Integer> {
@Query("SELECT m.id, o.total_amount FROM Member m JOIN m.orders o WHERE m.id = :memberId")
List<Member> findMemberWithOrders(@Param("memberId") int memberId);
}
it shows the error below
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.Integer] to type [@org.springframework.data.jpa.repository.Query com.testJoin.Jointest.Model.Member]
ive searched the answer for a while, and i found out most people uses the first way to retrieve it,
but im wondering if its possible to implement like the select a,b from … just like the sql command.
Is there anyway wrong or should be setup?
Im trying to join theses tables (or entity?) and retrieve the datas
My goal is to retreive the specific coulmns , like member.id, order_detail.total_amount
and send to the front instead of whole datas
user25523132 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.