سؤال

I have EJB 3.0 application. It is run on Jboss 7.1 server.

I have two persistence-unit in persistence.xml to work with two sql server.

I use first server for writing and updating tables. The second SQL server is only for reading data.

When I create Entity Classes in my application, it creates TABLES in BOTH OF THE SERVER.

I want to crate Entity objects only one server. How can I configure that? I don't need to create another EJB project. Is there any way?

<persistence-unit name="PHOTOS_DB">

        <jta-data-source>java:/MS_SQL_PHOTOS_DS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect"  value="org.hibernate.dialect.SQLServer2005Dialect"/>
            <property name="hibernate.cache.use_second_level_cache" value="true"/>
        </properties>
    </persistence-unit>


    <persistence-unit name="REPORTING_DB">
        <jta-data-source>java:/MS_SQL_REPORTING_DS</jta-data-source>
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.show_sql" value="true" />
            <property name="hibernate.dialect"  value="org.hibernate.dialect.SQLServer2005Dialect"/>
            <property name="hibernate.cache.use_second_level_cache" value="true"/>
        </properties>
    </persistence-unit>
هل كانت مفيدة؟

المحلول

We can use class and exclude-unlisted-classes tags, in order to map classes from XML. If we write exclude-unlisted-classes without class mapping, it skips entity mapping it to this DB.

<class>A.B.C.ClassName</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top