I'm having trouble importing data into a join table for a ManyToMany relationship using hbm2ddl. I'm using an in-memory HSQLDB for unit testing purposes. All the other tables have no trouble loading.
It seems like the insert statement is getting chopped prior to execution:
Code:
10:27:21,518 INFO [SchemaExport] Executing import script: worker_x_manager.sql
10:27:21,518 DEBUG [SchemaExport] insert into "WORKER_X_MANAGER" ("ID", "VERSION", "SUBORDINATE_WORKER_ID", "MANAGER_WORKER_ID") values (1, 1, 1, 2)
10:27:21,518 ERROR [SchemaExport] schema export unsuccessful
org.hibernate.JDBCException: Error during import script execution at line 1
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:370)
...
Caused by: java.sql.SQLException: Column count does not match in statement [insert into "WORKER_X_MANAGER" ("ID", "VERSION", "SUBORDINATE_WORKER_ID", "MANAGER_WORKER_ID")]
at org.hsqldb.jdbc.Util.sqlException(Unknown Source)
...
at org.hibernate.tool.hbm2ddl.SchemaExport.importScript(SchemaExport.java:366)
... 29 more
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
version="2.0">
<persistence-unit name="testPU" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<class>Address</class>
<class>Patient</class>
<class>Person</class>
<class>Schedule</class>
<class>State</class>
<class>Visit</class>
<class>Worker</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.url" value="jdbc:hsqldb:mem:unit-testing-jpa"/>
<property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect"/>
<property name="hibernate.hbm2ddl.auto" value="create-drop"/>
<property name="hibernate.connection.username" value="sa"/>
<property name="hibernate.connection.password" value=""/>
<property name="hibernate.show.sql" value="true"/>
<property name="hibernate.hbm2ddl.import_files" value="
state.sql,
person.sql,
address.sql,
patient.sql,
worker.sql,
visit.sql,
schedule.sql,
worker_x_manager.sql"/>
</properties>
</persistence-unit>
</persistence>
here is the definition within the Worker class ...
Code:
//bi-directional many-to-many association to Worker
@ManyToMany
@JoinTable(
name="WORKER_X_MANAGER"
, joinColumns={
@JoinColumn(name="MANAGER_WORKER_ID", nullable=false)
}
, inverseJoinColumns={
@JoinColumn(name="SUBORDINATE_WORKER_ID", nullable=false)
}
)
private List<Worker> managers;
//bi-directional many-to-many association to Worker
@ManyToMany(mappedBy="managers")
private List<Worker> subordinates;
Am I doing something wrong or did I stumble upon a bug?
Thanks,
Steve Maring