Java JPA:如何选择@Embeddeble类
我将从@Embeddeble Class Certification中选择所有列。但我不能选择它。如何选择可嵌入类Java JPA:如何选择@Embeddeble类,java,jpa,ejb-3.0,Java,Jpa,Ejb 3.0,我将从@Embeddeble Class Certification中选择所有列。但我不能选择它。如何选择可嵌入类 @Entity public class Department implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy = GenerationType.AUTO) private Long id; priv
@Entity
public class Department implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String name;
@ElementCollection
@CollectionTable(name = "Certification", joinColumns = {@JoinColumn(name="user_id")})
private List<Certification> certifications = new ArrayList<Certification>();
public List<Certification> getCertifications() {
return certifications;
}
public void setCertifications(List<Certification> certifications) {
this.certifications = certifications;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
.....
如果运行ResultService,会出现以下异常:
原因:java.lang.IllegalArgumentException:在EntityManager中创建查询时发生异常:
异常说明:编译查询时出错[从证书c中选择c]。未知的实体类型[证书]
如何选择@Embeddeble类?您需要通过真实实体类,即
部门
检索认证
。一个查询示例如下:
select cer from Department dep join dep.certifications cer
或者,您可能希望检索符合条件的部门实体,然后使用它们获取证书
select cer from Department dep join dep.certifications cer