How to make this choice * from two queries of related tables in the HQL form?

I had two sleep objects with annotation:

@Entity
@Table(name = "CLIENT")
public class Client {

    private Long pkClient;
    private String name;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @Column(name="PK_CLIENT")
    public Long getPkClient() {
        return pkClient;
    }
    public void setPkClient(Long pkClient) {
        this.pkClient = pkClient;
    }

    @Column(name="NAME")
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }

    ...
}

@Entity
@Table(name="ACCOUNT")
public class Account {

    private Long pkClientAccount;
    private Long fkClient;
    private String accountNo;

    @Id
    @Column(name="PK_CLIENT_ACCOUNT")
    @GeneratedValue(strategy=GenerationType.AUTO)
    public Long getPkClientAccount() {
        return pkClientAccount;
    }
    public void setPkClientAccount(Long pkClientAccount) {
        this.pkClientAccount = pkClientAccount;
    }

    @Column(name="FK_CLIENT")
    public Long getFkClient() {
        return fkClient;
    }
    public void setFkClient(Long fkClient) {
        this.fkClient = fkClient;
    }

    @Column(name="ACCOUNT_NO")
    public String getAccountNo() {
        return accountNo;
    }
    public void setAccountNo(String accountNo) {
        this.accountNo = accountNo;
    }

    ...
}

Relationship - one-to-many, which the Client has a lot of Account. The ACCOUNT table has a foreign key (FK_CLIENT) for writing the primary key CLIENT (PK_CLIENT).

I want to execute this query in HQL form:

select * from ACCOUNT a inner join CLIENT b on a.FK_CLIENT = b.PK_CLIENT

This means that all properties of the Account and Client object will be selected.

Does anyone know how to make this query in HQL form?

AFAIK, in HQL we can select only one entity.

Note:
I cannot use the @ManyToOne mapping in the Account object because there is already a fkClient property, and I cannot change this because get / setFkClient is already used elsewhere.

. , , .

+5
4

, HQL. Hibernate Object[].

select 
    account, 
    client 
from Account account, Client client 
where account.fkClient = client.pkClient
+14

Hibernate 5.1 , .

, HQL- Hibernate 5.1:

select 
    account, 
    client 
from Account account 
join Client client on account.fkClient = client.pkClient
+2

HQL

select account from Account account, Client client where account.fkClient = client.pkClient

. Hibernate http://docs.jboss.org/hibernate/orm/3.6/reference/en-US/html/queryhql.html#queryhql-where

0

:

select * from  TB_1 as a 
left join  TB_2 as b 
on a.ID_TB_1 = b.ID_TB_2 and b.ID_TB_2 is null 
0

All Articles