views:

102

answers:

1

Hi guys,

I have an application which manages 3 databases. I use hibernate with JPA on seam framework.

So I have a persitence.xml file with three persitence-unit like this (I remove properties for db2 and db3):

<persistence-unit name="db1" transaction-type="JTA" >
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>db1source</jta-data-source>
    <properties>
        <property name="hibernate.dialect"
            value="org.hibernate.dialect.Oracle10gDialect" />
        <property name="hibernate.connection.driver_class"
            value="oracle.jdbc.driver.OracleDriver" />
        <property name="hibernate.hbm2ddl.auto" value="validate" />
        <property name="hibernate.show_sql" value="false" />
        <property name="hibernate.format_sql" value="true" />
        <property name="hibernate.default_schema" value="SI_TEC" />
        <property name="hibernate.validator.apply_to_ddl" value="false" />
        <property name="hibernate.transaction.manager_lookup_class"
            value="org.hibernate.transaction.WeblogicTransactionManagerLookup" />
    </properties>
</persistence-unit>

<persistence-unit name="db2" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>d2source</jta-data-source>
</persistence-unit>

<persistence-unit name="db3" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>d3source</jta-data-source>
</persistence-unit>

In my seam components.xml file, I create 3 managed-persistence-context to map seam with my hibernate configuration.

Finally, I have several entities and my problem is here. I need to persist some entities in db2 and other in db3. So database schema are different and when I deploy my application, I get this error:

org.hibernate.HibernateException: Missing table: PORTAILPERMISSION
    at org.hibernate.cfg.Configuration.validateSchema(Configuration.java:1113)
    at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:139)
    at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:349)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1327)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:867)
    Truncated. see log file for complete stacktrace

Because, the table PORTAILPERMISSION doesn't exist in db2.

My question is:

How to specify in entity class what database (or persitence-unit) must be used to validate entity in startup ?

Thanks for your help.

+3  A: 

You try to explicitly list classes (<class>..</class>) in each persistence unit. And use

<exclude-unlisted-classes>true</exclude-unlisted-classes>
Bozho
How can I switch off auto-detection ?
Kiva
@Kiva see my update
Bozho
Thanks, I add this and all work fine :)
Kiva