Helo!
I am with a composed problem with foreign key.
Banco
osm_ordem_serv_man
- osm_nu_osm pk
- osmcd_veiculo fk
- osm_cd_emp_veiculo fk
vcl_veiculo
- vcl_cd_empresa pk
- vcl_cd_veiculo pk
Code:
<class name="br.bean.Osm" table="osm_ordem_serv_man">
<id name="numero" column="osm_nu_osm"/>
<many-to-one name="veiculo" class="br.bean.Veiculo"
insert="false" update="false">
<column name="osm_cd_veiculo"/>
<column name="osm_cd_emp_veic"/>
</many-to-one>
...
Code:
<class name="br.bean.Veiculo" table="vcl_veiculo">
<!--
<id name="codigo" column="vcl_cd_veiculo"/>
<property name="codigoEmpresa" column="vcl_cd_empresa" />
-->
<composite-id name="compositeID" class="br.bean.VeiculoID">
<key-many-to-one name="veiculo"
column="vcl_cd_veiculo"
class="br.bean.Veiculo"/>
<key-many-to-one name="empresa"
column="vcl_cd_empresa"
class="br.bean.Empresa"/>
</composite-id>
it gives the following error!
Code:
Initial SessionFactory creation failed.
org.hibernate.MappingException: Foreign key (FK47AECF2FCABA5BA0:vcl_veiculo [vcl_cd_veiculo])) must have same number of columns as the referenced primary key (vcl_veiculo [vcl_cd_veiculo,vcl_cd_empresa])
Exception in thread "main" java.lang.ExceptionInInitializerError
at br.util.HibernateUtil.<clinit>(HibernateUtil.java:32)
at br.dao.OsmDAO.excluir(OsmDAO.java:302)
at br.dao.OsmDAO.main(OsmDAO.java:439)
Caused by: org.hibernate.MappingException: Foreign key (FK47AECF2FCABA5BA0:vcl_veiculo [vcl_cd_veiculo])) must have same number of columns as the referenced primary key (vcl_veiculo [vcl_cd_veiculo,vcl_cd_empresa])
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:90)
at org.hibernate.mapping.ForeignKey.alignColumns(ForeignKey.java:73)
at org.hibernate.cfg.Configuration.secondPassCompileForeignKeys(Configuration.java:1123)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1062)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1146)
at br.util.HibernateUtil.<clinit>(HibernateUtil.java:26)
... 2 more
Process exited with exit code 1.
they alguem knows as to solve?