Hibernate version: 3.1.1
Mapping documents: Hibernate Annotations beta 8
Code between sessionFactory.openSession() and session.close(): Using Spring
Name and version of the database you are using: Oracle 10g (10.1.2)
The generated SQL (show_sql=true):
Hello there! I've really tried everthing here, I've posted at the EJB3 forum, and got no reply, please help me here!
I have entities that are mapped to views on oracle. Both of them have composite keys. I'm having problems when creating a OneToMany relationship between them. Here's some snippet of my code:
Code:
@Entity
@Table(name="VW_USUARIO")
@SuppressWarnings("serial")
public class Usuarioimplements BaseEntity {
private UsuarioPK id;
private String nome;
private Cidade cidade;
private Set<Produto> produtos;
@Id
public UsuarioPK getId() {
return id;
}
@Column(name="NOME")
public String getNome() {
return nome;
}
@ManyToOne(cascade=CascadeType.REFRESH)
@JoinColumn(name="CODCID")
public Cidade getCidade() {
return cidade;
}
@OneToMany(fetch=FetchType.EAGER,targetEntity=Produto.class,mappedBy="usuario")
@JoinColumns({@JoinColumn(name="CODCID"),@JoinColumn(name="CONTRA")})
public Set getProdutos() {
return produtos;
}
}
@Embeddable
public class UsuarioPK implements Serializable { ...} //it implements equals and hashcode
@SuppressWarnings("serial")
@Entity
@Table(name="VW_PRODUTO")
public class Produto implements BaseEntity {
private ProdutoPK id;
private Usuario usuario;
@Id
public ProdutoPK getId() {
return id;
}
@ManyToOne
public Usuario getUsuario() {
return usuario;
}
}
The problem here is that the SQL being generated adds a prefix to some of the join columns on the VW_PRODUTO I have the CODCID, CONTRA columns which are the FK from the Usuario View. Hibernate is prefixing this columns with the entity name:
Code:
select usuario0_.CONTRA as CONTRA3_3_, usuario0_.CODCID as CODCID3_3_, usuario0_.NOME as NOME3_3_, cidade1_.CODCID as CODCID2_0_, cidade1_.NOME as NOME2_0_, produtos2_.CODCID as CODCID5_, produtos2_.CONTRA as CONTRA5_, produtos2_.PONTO as PONTO5_, produtos2_.CONTRA as CONTRA4_1_, produtos2_.CODCID as CODCID4_1_, produtos2_.PONTO as PONTO4_1_, produtos2_.CODPROG as CODPROG4_1_, produtos2_.VALOR as VALOR4_1_, produtos2_.DTCONE as DTCONE4_1_, produtos2_.DTDESC as DTDESC4_1_, produtos2_.DESCRICAO as DESCRICAO4_1_, produtos2_.ID_STATUS as ID9_4_1_, produtos2_.LOCAL as LOCAL4_1_, produtos2_.usuario_CONTRA as usuario12_4_1_, produtos2_.usuario_CODCID as usuario13_4_1_, produtos2_.STATUS as STATUS4_1_, usuario3_.CONTRA as CONTRA3_2_, usuario3_.CODCID as CODCID3_2_, usuario3_.NOME as NOME3_2_ from VW_usuario usuario0_ left outer join TVA0600 cidade1_ on usuario0_.CODCID=cidade1_.CODCID left outer join VW_PONTO_PRODUTO produtos2_ on usuario0_.CONTRA=produtos2_.CODCID and usuario0_.CODCID=produtos2_.CONTRA left outer join VW_usuario usuario3_ on produtos2_.usuario_CONTRA=usuario3_.CONTRA and produtos2_.usuario_CODCID=usuario3_.CODCID where usuario0_.CONTRA=? and usuario0_.CODCID=?
As shown above produtos2_.CODCID as CODCID5_ is being selected but also produtos2_.usuario_CODCID
Could someone please help me here, If any other info is need I can provide at any time.