Boa Tarde estou tendo a seguinte exception:
Caused by: org.hibernate.AnnotationException: Referenced property not a (One|Many)ToOne: br.com.xxx.modelo.TbTabelaB.idtabelaa in mappedBy of br.com.xxx.modelo.TbTabelaA.tbTabelaB
at org.hibernate.cfg.OneToOneSecondPass.doSecondPass(OneToOneSecondPass.java:203)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1163)
at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:329)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:673)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1369)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1335)
… 46 more
SCRIPT SQL + CLASSE
create table TB_TABELAA
(
id integer not null,
descricao varchar(40) character set WIN1252 not null collate PXW_INTL850,
constraint PRKTB_TABELAA primary key(ID)
);
insert into TB_TABELAA (ID,DESCRICAO) values (1,‘TabelaA1’);
insert into TB_TABELAA (ID,DESCRICAO) values (2,‘TabelaA2’);
@Entity
@Table(name=“TB_TABELAA”)
public class TbTabelaA {
@Id
private Integer id;
@NotNull
@Column(length=40, columnDefinition=“varchar(40)”, nullable=false)
@Length(min=3, max=40)
private String descricao;
@OneToOne(mappedBy=“idtabelaa”)
private TbTabelaB tbTabelaB;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
public TbTabelaB getTbTabelaB() {
return tbTabelaB;
}
public void setTbTabelaB(TbTabelaB tbTabelaB) {
this.tbTabelaB = tbTabelaB;
}
}
SCRIPT SQL + CLASSE
create table TB_TABELAB
(
idtabelaa integer not null,
descricao varchar(40) character set WIN1252 not null collate PXW_INTL850,
constraint PRKTB_TABELAB primary key(IDTABELAA),
constraint FRKTB_TABELAB foreign key(IDTABELAA) references TB_TABELAA(ID) on update cascade
);
insert into TB_TABELAB (IDTABELAA,DESCRICAO) values (1,‘TabelaB1’);
insert into TB_TABELAB (IDTABELAA,DESCRICAO) values (2,‘TabelaB2’);
@Entity
@Table(name=“TB_TABELAB”)
public class TbTabelaB {
@Id
@OneToOne(cascade={CascadeType.ALL})
@JoinColumn(name=“idtabelaa”)
private TbTabelaA idtabelaa;
@Length(min=2, max=40)
@Column(length=40, columnDefinition=“varchar(40)”, nullable=false)
@NotNull
private String descricao;
public TbTabelaA getIdtabelaa() {
return idtabelaa;
}
public void setIdtabelaa(TbTabelaA idtabelaa) {
this.idtabelaa = idtabelaa;
}
public String getDescricao() {
return descricao;
}
public void setDescricao(String descricao) {
this.descricao = descricao;
}
}