22.10.25 17:47 작성
·
254
0
public void 임베디드값조회(){
List list = em.createQuery("select m.addressList from Member m").getResultList();
for (Object o : list) {
System.out.println(o);
}
}
다음과 같은 오류가 뜹니다
not an entity [select m.addressList from jpaStudy.ex.entity.Member m]
근데 m.addressList가 엔티티는 당연히 아니잖아요?
왜 저 문장에 오류가 있는건가요? addresslist는 강의에 나온 address의 list버전입니다.
답변 3
0
2022. 11. 04. 13:55
package jpaStudy.ex.entity;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import javax.persistence.Embeddable;
@Embeddable
@AllArgsConstructor
@NoArgsConstructor
@Getter
public class Address {
private String zipCode;
private String code;
}
package jpaStudy.ex.entity;
import lombok.*;
import javax.persistence.*;
import java.util.List;
@Entity
@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor
@NamedQuery(
name = "Member.findByUsername",
query = "select m from Member m where m.name = :name"
)
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "MEMBER_ID")
private Long id;
@Column
private String name;
private Integer age;
@ElementCollection
@CollectionTable(name = "Address", joinColumns = @JoinColumn(name = "MEMBER_ID"))
private List<Address> addressList;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "team_id")
private Team team;
@ManyToOne
@JoinColumn(name = "group1_id")
private Group1 group1;
@Embedded
private Address myAddress;
}