私はこのテーブルを持っています:
1.- 参加者
CREATE TABLE participante (
id_participa SMALLINT NOT NULL,
nasi INTEGER NOT NULL,
PRIMARY KEY(id_participa,nasi),
FOREIGN KEY(nasi) REFERENCES persona(nasi)
)
2.-ペルソナ
CREATE TABLE persona (
nasi INTEGER NOT NULL,
PRIMARY KEY(nasi)
)
3.- CITA
CREATE TABLE cita (
id_participa SMALLINT NOT NULL,
nasi INTEGER NOT NULL,
idcita INTEGER NOT NULL,
PRIMARY KEY(id_participa,idcita,nasi),
FOREIGN KEY(id_participa, nasi) REFERENCES participante(id_participa, nasi)
)
4.- フォーミュラリオ
CREATE TABLE formulario (
id_participa SMALLINT NOT NULL,
nasi INTEGER NOT NULL,
idcita INTEGER NOT NULL,
PRIMARY KEY(id_participa,idcita,nasi),
FOREIGN KEY(id_participa, nasi, idcita) REFERENCES cita(id_participa, nasi, idcita)
)
(他の分野の中でも、問題に関与しているものだけを紹介します)
エンティティは次のとおりです。
1.- 参加者
@Entity
@Table(name = "participante")
public class Participante implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "id_participa")
private Integer idParticipante;
@Id
@OneToOne
@JoinColumn(name = "nasi")
private Persona persona;
2.-ペルソナ
@Entity
@Table(name = "persona")
public class Persona implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "nasi")
private Integer nasi;
3.- CITA
@Entity
@Table(name = "cita")
public class Cita implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "idcita")
private Integer idCita;
@Id
@ManyToOne
@JoinColumns({
@JoinColumn(name = "id_participa", referencedColumnName = "id_participa"),
@JoinColumn(name = "nasi", referencedColumnName = "nasi") })
private Participante participante;
4.- フォーミュラリオ
@Entity
@Table(name = "formulario")
public class Formulario implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@OneToOne
@JoinColumns({
@JoinColumn(name = "id_participa", referencedColumnName = "id_participa"),
@JoinColumn(name = "nasi", referencedColumnName = "nasi"),
@JoinColumn(name = "idcita", referencedColumnName = "idcita") })
private Cita cita;
サーバーを起動しようとすると、次の例外が発生しました。
Caused by: org.hibernate.MappingException: Unable to find column with logical name: nasi in participante
at org.hibernate.cfg.Ejb3JoinColumn.checkReferencedColumnsType(Ejb3JoinColumn.java:575)
at org.hibernate.cfg.BinderHelper.createSyntheticPropertyReference(BinderHelper.java:126)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:116)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 73 more
編集:注釈から「referencedColumn」属性を削除すると、別の例外が発生することがわかりました:
Caused by: org.hibernate.AnnotationException: A Foreign key refering es.myapp.modelo.datos.dominio.participante.Participante from es.myapp.modelo.datos.dominio.cita.Cita has the wrong number of column. should be 1
at org.hibernate.cfg.annotations.TableBinder.bindFk(TableBinder.java:432)
at org.hibernate.cfg.ToOneFkSecondPass.doSecondPass(ToOneFkSecondPass.java:117)
at org.hibernate.cfg.Configuration.processEndOfQueue(Configuration.java:1514)
at org.hibernate.cfg.Configuration.processFkSecondPassInOrder(Configuration.java:1437)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1355)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1724)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1775)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:242)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:357)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452)
... 73 more