我有两个实体:
@Entity
@Table(name = "T_CLIENT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Client implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "code")
private String code;
@Column(name = "nom")
private String nom;
@OneToOne
private TypeClient typeClient;
@Entity
@Table(name = "T_TYPECLIENT")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class TypeClient implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@Column(name = "nom")
private String nom;
我想做那个查询:
@Query("Select id, nom, code, codeComptable, typeClient from Client")
List<Object[]> findAllWithoutForeignKey();
JPA仅返回typeClient&lt;&gt;的客户端空。
如何获得所有客户?
感谢。
答案 0 :(得分:1)
这是因为您的查询会在inner join
和Client
之间转换为TypeClient
。试试这个
@Query("Select c.id, c.nom, c.code, c.codeComptable, tc from Client c left join c.typeClient tc")
答案 1 :(得分:0)
与TypeClient的Client
关系不是OneToOne
,而是ManyToOne
。尝试改变它,它可能会起作用。