我在为Hibernate,Spring,Oracle数据库(本地创建)配置测试环境时遇到了一些问题。所有bean通常在启动时初始化,除了" sessionFactory"。这个例外让我感到困惑:
Caused by: org.hibernate.AnnotationException: Cannot find the expected secondary table: no MY_INFORMATION available for net.me.business.model.MyInformation
at org.hibernate.cfg.Ejb3Column.getJoin(Ejb3Column.java:358) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Ejb3Column.getTable(Ejb3Column.java:337) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Ejb3Column.toString(Ejb3Column.java:621) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Ejb3Column.bind(Ejb3Column.java:192) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Ejb3Column.buildColumnFromAnnotation(Ejb3Column.java:473) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Ejb3Column.buildColumnFromAnnotation(Ejb3Column.java:389) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.ColumnsBuilder.extractMetadata(ColumnsBuilder.java:94) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1495) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.AnnotationBinder.processIdPropertiesIfNotAlready(AnnotationBinder.java:796) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:707) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processAnnotatedClassesQueue(Configuration.java:4035) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Configuration$MetadataSourceQueue.processMetadata(Configuration.java:3989) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1398) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1375) ~[hibernate-core-3.6.8.Final.jar:3.6.8.Final]
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717) ~[spring-orm-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:188) ~[spring-orm-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1514) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1452) ~[spring-beans-3.1.1.RELEASE.jar:3.1.1.RELEASE]
这是休眠/弹簧配置:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"
p:dataSource-ref="dataSource" p:packagesToScan="net.me.business.model" p:hibernateProperties-ref="hibernateProperties" />
<util:properties id="hibernateProperties">
<prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<!--<prop key="hibernate.connection.url">jdbc:h2:mem:test;INIT=create schema if not exists myschema\;SET SCHEMA myschema\;MODE=Oracle;DB_CLOSE_DELAY=-1</prop>-->
<!--<prop key="hibernate.hbm2ddl.auto">update</prop>-->
</util:properties>
我不知道我在哪里错过了什么。
这是github repo。请看一下:
https://github.com/slavisah/mybusiness.git
README.md中有一些注释
有没有办法动态地将相同的序列映射作为ID生成器添加到每个表中?无需在每个班级编写注释。序列名称模板将是[tablename] _SEQ。
答案 0 :(得分:1)
我已经弄明白我在哪里做错了。这两个人不在一起:
@Table(name="ADDRESS")
public class Address implements Serializable {
@Column(name="MODIFIED_BY",table="ADDRESS",length=100)
@Basic
private String modifiedBy;
}
在课程开始时 @Table(name="ADDRESS")
,在每个字段上@Column(...table="ADDRESS"...)
。此映射由JPA Modeler netbeans插件生成。我不会再依赖它了:)
问题#2 仍然可供讨论。
谢谢大家。
答案 1 :(得分:0)
目前,JPA Modeler正在开发中。因此,请使用JPA Modeler xml的附件提出您的错误here。 谢谢你的贡献!