NoPrimaryKeyException from DBUnit when loading a dataset into a database

I get a NoPrimaryKeyException when I try to run one of my unit tests that uses DBUnit. The data type is created using Hibernate and is a table of joins between two classes representing the relationships of many, many. The annotations that define the relationship are as follows:

@Override
@ManyToMany
@JoinTable(name="offset_file_offset_entries", joinColumns={@JoinColumn(name="offset_entry_id")},inverseJoinColumns={@JoinColumn(name="file_description_id")})
public List<OffsetEntry> getOffsets() {

Other entries in the XML file that I use to define the dataset work fine, but not in the join table. I get the following exception:

org.dbunit.dataset.NoPrimaryKeyException: offset_file_offset_entries
    at org.dbunit.operation.UpdateOperation.getOperationData(UpdateOperation.java:72)
    at org.dbunit.operation.RefreshOperation$UpdateRowOperation.<init>(RefreshOperation.java:266)
    at org.dbunit.operation.RefreshOperation.createUpdateOperation(RefreshOperation.java:142)
    at org.dbunit.operation.RefreshOperation.execute(RefreshOperation.java:100)
    at org.dbunit.ext.mssql.InsertIdentityOperation.execute(InsertIdentityOperation.java:217)
    at uk.co.sabio.obscheduler.application.dao.AbstractBaseDatabaseTest.setUp(AbstractBaseDatabaseTest.java:57)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runManaged(AbstractJUnit38SpringContextTests.java:332)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.access$0(AbstractJUnit38SpringContextTests.java:326)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests$1.run(AbstractJUnit38SpringContextTests.java:216)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTest(AbstractJUnit38SpringContextTests.java:296)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTestTimed(AbstractJUnit38SpringContextTests.java:253)
    at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runBare(AbstractJUnit38SpringContextTests.java:213)
    at junit.framework.TestResult$1.protect(TestResult.java:110)
    at junit.framework.TestResult.runProtected(TestResult.java:128)
    at junit.framework.TestResult.run(TestResult.java:113)
    at junit.framework.TestCase.run(TestCase.java:124)
    at junit.framework.TestSuite.runTest(TestSuite.java:232)
    at junit.framework.TestSuite.run(TestSuite.java:227)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

The corresponding Dataset entry is as follows:

<offset_file_offset_entries offset_entry_id="1" file_description_id="1" />

And it maps to a database that has both fields as primary keys (The Databse is MS SQL Server, if that helps). Corresponding entries in the two tables specified in the following xml:

<dataset>
    <file_description file_path="src/test/resources/" file_pattern=".txt" file_description_id="1"/>
    <offset_file_description file_description_id="1"/>
    <offset_entries offset_entry_id="1" field_name="Field1" field_length="10" start_index="0"/>
    <offset_file_offset_entries offset_entry_id="1" file_description_id="1" />  
</dataset>

? , ? , , , ?

DBUnit, , .

+3
1

? , ?

, , , Hibernate/JPA . , , ( ) @Id .

+2

Source: https://habr.com/ru/post/1734055/


All Articles