所以我收到了这个错误:
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>
有什么想法吗?
答案 0 :(得分:1)
我自己解决了这个问题。我不得不将这个JPA注释添加到父类:
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class Car {