shx
shx

Reputation: 1138

org.hibernate.AnnotationException: Cannot find the expected secondary table

I'm having some problems with configuring testing environment for Hibernate, Spring, Oracle database (created locally). All beans are normally initialized at startup except "sessionFactory". This exception bugs me:

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]

This is hibernate/spring configuration:

<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>

I don't have any idea where did I missed something.

Here is github repo. Please take a look:

https://github.com/slavisah/mybusiness.git

There are some notes in README.md

Question #2

Is there any way to dynamically add same sequence mapping as a ID generator to every table? Without writing annotations in every class. The sequence name template would be [tablename]_SEQ.

Upvotes: 0

Views: 4851

Answers (2)

jGauravGupta
jGauravGupta

Reputation: 155

Currently JPA Modeler is in development . So please raise your bug here with the attachment of JPA Modeler xml . Thanks for your contribution !

Upvotes: 0

shx
shx

Reputation: 1138

I've figured it out where I'm doing wrong. These two don't go together:

@Table(name="ADDRESS")
public  class Address implements Serializable {


    @Column(name="MODIFIED_BY",table="ADDRESS",length=100)
    @Basic
    private String modifiedBy;


}

@Table(name="ADDRESS") at the beginning of the class and @Column(...table="ADDRESS"...) on every single field. This mapping was generated by JPA Modeler netbeans plugin. I will not rely on it any more :)

Question #2 from above is still open for discussion.

Thanks everybody.

Upvotes: 1

Related Questions