Java @索引对连接的子类不起作用?

Java @索引对连接的子类不起作用?,java,hibernate,junit,hibernate-annotations,Java,Hibernate,Junit,Hibernate Annotations,当我的应用程序在服务器上运行时,我的Hibernate注释可以工作,但是当我尝试使用JUnit测试我的Hibernate类时,我得到以下错误: org.hibernate.MappingException: Unable to find column with logical name base_batch_id in table T_BASE_EXT at org.hibernate.cfg.Configuration$MappingsImpl.getPhysicalColumnName(Co

当我的应用程序在服务器上运行时,我的Hibernate注释可以工作,但是当我尝试使用JUnit测试我的Hibernate类时,我得到以下错误:

org.hibernate.MappingException: Unable to find column with logical name base_batch_id in table T_BASE_EXT
at org.hibernate.cfg.Configuration$MappingsImpl.getPhysicalColumnName(Configuration.java:3550)
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.addConstraintToColumn(IndexOrUniqueKeySecondPass.java:87)
at org.hibernate.cfg.IndexOrUniqueKeySecondPass.doSecondPass(IndexOrUniqueKeySecondPass.java:77)
at org.hibernate.cfg.Configuration.originalSecondPassCompile(Configuration.java:1716)
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1423)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1856)
at foo.BaseTest.setUp(BaseTest.java:31)
at junit.framework.TestCase.runBare(TestCase.java:125)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
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)
我相信这与
BaseExt
类中的
@Index
注释有关。我的带注释的类正在工作,无法更改它们,但是在JUnit测试中我是否可以对我的Hibernate配置做些什么来让它工作

我发现了一张有类似问题的票:

下面是复制此错误的JUnit测试:

抽象基类:

@MappedSuperclass
公共抽象类基类实现了可序列化{
私有静态最终长serialVersionUID=1L;
@身份证
@SequenceGenerator(name=“SEQ_GEN”,sequenceName=“SEQ”,initialValue=1)
@GeneratedValue(策略=GenerationType.AUTO,generator=“SEQ_GEN”)
私人长id;
公共长getId(){
返回id;
}
公共无效集合id(长id){
this.id=id;
}
}
扩展抽象类的类:

它还与BaseBatch类有多个关系

@实体
@表(name=“T\u BASE\u EXT”)
@表(appliesTo=“T\u BASE\u EXT”,索引={
@索引(name=“IDX\u CDA\u 1”,columnNames={“BASE\u BATCH\u ID”})
})
公共类BaseExt扩展了基本实现java.io.Serializable{
私有静态最终长serialVersionUID=1L;
@ManyToOne(可选=false,fetch=FetchType.LAZY)
@ForeignKey(name=“CDA\U BASE\U BATCH\U FK”)
私有基批;
public BaseBatch getBaseBatch(){
返回基批;
}
public void setBaseBatch(BaseBatch BaseBatch){
this.baseBatch=baseBatch;
}
}
BaseBatch:

@实体
@表(name=“T_BASE_BATCH”)
公共类BaseBatch扩展了基本实现java.io.Serializable{
私有静态最终长serialVersionUID=1L;
}
JUnit测试:

公共类BaseTest扩展了TestCase{
私有SessionFactory SessionFactory=null;
@凌驾
受保护的void setUp()引发异常{
super.setUp();
最终字符串driverClass=“org.hsqldb.jdbcDriver”;
试一试{
类forName(driverClass);
}catch(classnotfounde异常){
e、 printStackTrace();
}
配置cfg=新配置()
.setProperty(“hibernate.dialent”、“org.hibernate.dialent.hsqldialent”)
.setProperty(“hibernate.connection.driver_类”,driverClass)
.setProperty(“hibernate.connection.url”,“jdbc:hsqldb:mem:basetest”)
.setProperty(“hibernate.hbm2ddl.auto”、“create”);
addAnnotatedClass(Base.class);
addAnnotatedClass(BaseExt.class);
addAnnotatedClass(BaseBatch.class);
sessionFactory=cfg.buildSessionFactory();
}
@凌驾
受保护的void tearDown()引发异常{
super.tearDown();
sessionFactory.close();
}
公共void testBase(){
sessionFactory.openSession();
资产真实(真实);
}
}

我使用的是Hibernate Annotations 3.2.0.Final和Hibernate 3.6.9.Final

@AttributeOverride(name="id", column=@Column(name="base_batch_id"))
private BaseBatch baseBatch;

谢谢添加AttributeOverride注释很有帮助,但我不得不将覆盖添加为类注释。(投票给你:)