Hello,
I have these relations:
EmpresaProfissionalDTO
Code:
@Entity
@Table(name="\"sim-empresa-prof\"", schema="PUB")
public class EmpresaProfissionalDTO implements Serializable {
@Id
@Column(name = "\"num-empresa-prof\"")
private String sqEmpresaProfissional;
@Column(name = "cargo")
private String cargo;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="\"num-profissional\"", insertable = false, updatable = false)
private ProfissionalDTO profissional;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name="cnpj", insertable = false, updatable = false)
private EmpresaDTO empresa;
ProfissionalDTO
Code:
@Entity
@Table(name="\"sim-profissional\"", schema="PUB")
public class ProfissionalDTO implements Serializable {
@Id
@Column(name = "\"num-profissional\"")
private Long sqProfissional;
@OneToMany(targetEntity = EmpresaProfissionalDTO.class ,mappedBy="profissional", cascade= javax.persistence.CascadeType.ALL)
@Cascade(value = CascadeType.DELETE_ORPHAN)
@Fetch(FetchMode.SUBSELECT)
private Set<EmpresaProfissionalDTO> empresaProfissional;
EmpresaDTO
Code:
@Entity
@Table(name="\"sim-empresa\"", schema="PUB")
public class EmpresaDTO implements Serializable {
@Id
@Column(name = "cnpj")
private String cnpj;
@OneToMany(mappedBy="empresa", cascade= javax.persistence.CascadeType.ALL)
@Cascade(value = CascadeType.DELETE_ORPHAN)
@Fetch(FetchMode.SUBSELECT)
private Set<EmpresaProfissionalDTO> empresaProfissional;
The EmpresaProfissionalDTO is the relation between ProfissionalDTO and EmpresaDTO.
I make this:
Code:
StringBuffer sb = new StringBuffer(" FROM ProfissionalDTO as c");
sb.append(" left join c.empresaProfissional s ");
sb.append(" where c.sqProfissional = :pChave ");
Query q = session.createQuery(sb.toString());
q.setLong("pChave", chave);
result = (ProfissionalDTO) q.uniqueResult();
but the hibernate don't put the "" in the left join... the select created by hibernate is this:
Code:
select columns..... (just cut because the size..)
from PUB."sim-profissional" profission0_
left outer join PUB."sim-empresa-prof" empresapro1_ on profission0_."num-profissional" =
empresapro1_.num-profissional
where profission0_."num-profissional" = ?
see in left outer join...
profission0_."num-profissional" = empresapro1_.
num-profissional
he dont put the "", and makes return a Exception, because he dont find that column..
How can I make this works?
Ps: I can't change the name of tables and columns... =/
Sorry my bad english...