0

所以我收到了这个错误:

org.dbunit.dataset.NoSuchColumnException: TOYOTA.CAR_MAKE -  (Non-uppercase input column: CRTE_DT_TM) in ColumnNameToIndexes cache map. Note that the map's column names are NOT case sensitive.

在 Spring JUnit 测试的上下文中尝试使用 DbUnit 填充 H2 DB 时。H2 DB 的 DDL 是从 JPA 注释类创建的。但是,该列确实存在,它位于由核心类扩展的抽象类中。

让我解释。核心 JPA 类如下所示:

@Entity
@Table(name = "TOYOTA")
public class Toyota extends Car {

    @Id
    @Column(name = "TOYOTA_REF")
    private String toyotaRef;

    @Column(name = "TOYOTA_DEALER")
    private String toyotaDealer;
// etc.

父类如下所示:

public abstract class Car {

    @Column(name = "CAR_MAKE")
    private String carMake;

    @Column(name = "CAR_MODEL")
    private String carModel;

我正在启动这样的测试:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/test-spring-config.xml") // Load Spring Test context
@TestExecutionListeners({DependencyInjectionTestExecutionListener.class,
        TransactionalTestExecutionListener.class,
        DbUnitTestExecutionListener.class}) // Used to load test data onto DB})

@DatabaseSetup(value = {"classpath:/integrationTestData/Toyota.xml"})
@Test
@Transactional

public void testSomething() {

我的 Toyota.xml 数据文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>

<dataset>
    <TOYOTA TOYOTA_REF="TOY123"
           TOYOTA_DEALER="Big Dealer"
           CAR_MAKE="Toyota"
           CAR_MODEL="Corolla"
           />
</dataset>

有什么想法吗?

4

1 回答 1

1

自己解决了这个问题。我必须将此 JPA 注释添加到父类:

import javax.persistence.MappedSuperclass;

@MappedSuperclass
public abstract class Car {
于 2015-08-12T10:32:53.637 回答