Hibernate version: 3.1.3
Hibernate annotations version: 3.1beta8
Name and version of the database you are using: mysql 4.1.12a
Dialect: org.hibernate.dialect.MySQLInnoDBDialect
Hi,
I am having a problem when embedding an object using the @Embedded annotation. The problem is that Hibernate does not correctly map the embedded class attributes. I think this could be related to the fact that the embedded object is a subclass and the mapped attribute is present in the superclass. Here is my code:
Code:
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Conteudo implements Serializable {
private Long id;
// more code
private ConteudoImagem imagem;
// more code
@Id @GeneratedValue
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Embedded
public ConteudoImagem getImagem(){
return imagem;
}
public void setImagem(ConteudoImagem img) {
imagem = img;
}
My embeddable class:
Code:
@Embeddable
public class ConteudoImagem extends Imagem{
// more code
@Transient
public String getGrande(){
return getImagemPath(GRANDE);
}
@Transient
public String getMedia(){
return getImagemPath(MEDIA);
}
@Transient
public String getPequena(){
return getImagemPath(PEQUENA);
}
// more code
}
The superclass of my embeddable class:
Code:
@Embeddable
public abstract class Imagem implements Serializable {
private String imagem;
// more code
public String getImagem(){
return imagem;
}
public void setImagem(String img){
imagem=img;
}
// more code
}
My conteudo table should be mapped like this:
Code:
create table Conteudo (id bigint not null auto_increment, ... , imagem varchar(255) ... ) type=InnoDB;
but, for some reason, the "imagem" attribute inherited by ConteudoImagem is not mapped at all.
However, if I override the Imagem.getImagem() method in ConteudoImagem like this:
Code:
@Embeddable
public class ConteudoImagem extends Imagem{
// more code
@Override
public String getImagem(){
return super.getImagem();
}
@Transient
public String getGrande(){
return getImagemPath(GRANDE);
}
@Transient
public String getMedia(){
return getImagemPath(MEDIA);
}
@Transient
public String getPequena(){
return getImagemPath(PEQUENA);
}
// more code
}
Then the "imagem" attribute is correctly mapped. Please, notice that in the second version of ConteudoImagem I override the Imagem.getImagem() method. That's why I think the problem might be related to inheritance.
Another funny thing is that everything works fine if I remove the @Embedded annotation from the Conteudo.getImagem() method.
Can anyone help me?
Thanks,
Jair[/code]