所以我得到这个错误:
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数据库的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>
任何想法吗?
自行修复。我必须将这个JPA注释添加到父类:
import javax.persistence.MappedSuperclass;
@MappedSuperclass
public abstract class Car {