Hi,
I've been using DBUnit very happily to insert data for testing. At the moment it acquires the connection through Hibernate (see bottom) and inserts using it's own tools.
This works for everything except the one table that corresponds to two POJOs (one extends the other) and I can't work out why. It may be entirely a DBUnit issue (in which case I apologise for asking) but I was wondering if anyone else had encountered this obscure problem.
In the below mapping fk_role_id is not inserted from the xml set below that (role is inserted fine previous to this). Could it be because fk_role_id is actually in "virtual" table user_role_access (as opposed to the user_access that DBUnit requests?)
Seems a bit far fetched to me but I am ruling out possibilities...
(normal usage of everything is AOK, this is strictly a DBunit issue)
c
library versions:
Hibernate 2.1.6
DBUnit 2.1
Postgresql 7.4.2
Mapping documents:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping
>
<class
name="net.sportplan.model.UserAccess"
table="user_access"
discriminator-value="USER"
>
<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="increment">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-UserAccess.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<discriminator
column="discriminator"
/>
<version
name="version"
type="java.lang.Integer"
column="version"
access="property"
unsaved-value="undefined"
/>
<many-to-one
name="access"
class="net.sportplan.model.Access"
cascade="none"
outer-join="auto"
column="fk_access_id"
not-null="true"
/>
<many-to-one
name="user"
class="net.sportplan.model.User"
cascade="none"
outer-join="auto"
column="fk_user_id"
not-null="true"
/>
<many-to-one
name="invoice"
class="net.sportplan.model.Invoice"
cascade="none"
outer-join="auto"
column="fk_invoice_id"
not-null="true"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserAccess.xml
containing the additional properties and place it in your merge dir.
-->
<subclass
name="net.sportplan.model.UserRoleAccess"
discriminator-value="ROLE"
>
<many-to-one
name="role"
class="net.sportplan.model.Role"
cascade="none"
outer-join="auto"
column="fk_role_id"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-UserRoleAccess.xml
containing the additional properties and place it in your merge dir.
-->
</subclass>
</class>
</hibernate-mapping>
flat data_set.xml
<user_access id="2" discriminator="ROLE" version="0" fk_role_id="1" fk_access_id="2" fk_user_id="1" fk_invoice_id="1" />
TestCase extending DBUnit code
protected IDatabaseConnection getConnection() throws Exception {
DataSource dataSource = (DataSource) ctx
.getBean("dataSource");
return new DatabaseConnection(dataSource.getConnection());
}
|