Reputation: 3429
I have two entities :
@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;
I want to do that query :
@Query("Select id, nom, code, codeComptable, typeClient from Client")
List<Object[]> findAllWithoutForeignKey();
JPA returns only client with typeClient <> null.
How do I have to do to get all clients?
Thanks.
Upvotes: 1
Views: 89
Reputation: 19002
The relationship Client
to TypeClient is not OneToOne
, but rather ManyToOne
. Try changing that, and it might work.
Upvotes: 0
Reputation: 24433
That's because your query translates to inner join
between Client
and TypeClient
. Try this
@Query("Select c.id, c.nom, c.code, c.codeComptable, tc from Client c left join c.typeClient tc")
Upvotes: 1