My database is :
TABLE1
"FILE_ID" NUMBER NOT NULL ENABLE,
"GEO_ZONE" VARCHAR2(2 BYTE) NOT NULL ENABLE,
PRIMARY KEY ("FILE_ID", "GEO_ZONE")
TABLE2
"FILE_ID" NUMBER NOT NULL ENABLE,
"GEO_ZONE" VARCHAR2(2 BYTE) NOT NULL ENABLE,
"RECORD_NUM" NUMBER,
PRIMARY KEY ("FILE_ID", "GEO_ZONE", "RECORD_NUM"),
CONSTRAINT "FK_8ULB8IEBEU6A0VK1WTNQA3MCY" FOREIGN KEY ("FILE_ID", "GEO_ZONE")
We can have multiple rows in Table2 for 1 in Table1.
My TABLE1 entity is:
@Entity
@Table(name = "TABLE1")
@IdClass(Table1Id.class)
public class Table1Entity implements Serializable {
private static final long serialVersionUID = 7825109721507305471L;
@Id
@Column(name = "FILE_ID", insertable = false, updatable = false)
private Long fileId;
@Id
@Column(name = "GEO_ZONE", insertable = false, updatable = false)
private String geoZone;
... Others attributes and getter and setter
My Table1Id class is:
public class Table1Id implements Serializable {
private static final long serialVersionUID = -8618317422024959144L;
private Long fileId;
private String geoZone;
... Others attributes and getter and setter
My TABLE2 entity is:
@Entity
@Table(name = "TABLE2")
@IdClass(Table2Id.class)
public class Table2Entity implements Serializable {
private static final long serialVersionUID = -1344497166638156145L;
@Id
@Column(name = "FILE_ID", insertable = false, updatable = false)
private Long fileId;
@Id
@Column(name = "GEO_ZONE", insertable = false, updatable = false)
private String geoZone;
@Id
@Column(name = "RECORD_NUM")
private Long recordNum;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumns({@JoinColumn(name = "FILE_ID", insertable = false, updatable = false), //
@JoinColumn(name = "GEO_ZONE", insertable = false, updatable = false)})
private Table1Entity table1Entity;
... Others attributes and getter and setter
My Table2Id class is:
public class Table2Id implements Serializable {
private static final long serialVersionUID = -4599660767213338871L;
private Long fileId;
private String geoZone;
private Long recordNum;
... Others attributes and getter and setter
When I try to launch my tomcat, I have the following error:
org.hibernate.MappingException: Foreign key (FK_8ulb8iebeu6a0vk1wtnqa3mcy:TABLE2 [FILE_ID,GEO_ZONE])) must have same number of columns as the referenced primary key (TABLE1 [FILE_ID])
I tried with referenced column, with primary key join column, and many others things but by reading it on internet, it can database modelization problem. I think the problem is that primary key and foreign key have the same name in the 2 tables but I can be wrong... I ask you to confirm it or if you have solution.
Thanks you by advance because 1 week I search to find solution but none of solutions I find work.
EDIT: I changed Table name to toto which doesn't exist in my base and I have the same error with another fk id. It seems hibernate doesn't connect to my database. But if I remove composite key from TABLE1 to have only file_id in join_column in Table2Entity and projects works but it's not what I want. It makes me sick, I don't understand where is the problem at all. And error tells that RDJ_STAT pk is only FILE_ID but no, like if hibernate is drunk
EDIT2 : Is it possible that ojdbc version can be a problem ? And no solution ?
EDIT3 :
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/data/jpa
http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd"
xmlns:jpa="http://www.springframework.org/schema/data/jpa">
<context:property-placeholder location="classpath:application.properties" />
<context:annotation-config/>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${db.driver}" />
<property name="url" value="${db.url}" />
<property name="username" value="${db.username}" />
<property name="password" value="${db.password}" />
</bean>
<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
<property name="showSql" value="true"/>
<property name="generateDdl" value="true"/>
<property name="database" value="MYSQL"/>
</bean>
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
<property name="persistenceXmlLocation" value="classpath:persistence.xml"></property>
<!-- spring based scanning for entity classes>-->
</bean>
<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>
<tx:annotation-driven transaction-manager="txManager" proxy-target-class="true"/>
<jpa:repositories base-package="com.sacre.repository" entity-manager-factory-ref="entityManagerFactory" transaction-manager-ref="transactionManager"/>
</beans>