论坛首页 编程语言技术论坛

seam中使用多数据源

浏览 1922 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-04-01   最后修改:2009-04-01

现在项目组使用seam技术,我在开发multiple 数据源问题,

1 components.xml 配置

<?xml version="1.0" encoding="UTF-8"?>
<components xmlns="http://jboss.com/products/seam/components"
	xmlns:core="http://jboss.com/products/seam/core"
	xmlns:persistence="http://jboss.com/products/seam/persistence"
	xmlns:transaction="http://jboss.com/products/seam/transaction"
	xmlns:security="http://jboss.com/products/seam/security"
	xmlns:bpm="http://jboss.com/products/seam/bpm"
	xmlns:web="http://jboss.com/products/seam/web"
	xmlns:spring="http://jboss.com/products/seam/spring"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:mail="http://jboss.com/products/seam/mail"
    xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.1.xsd 
                 http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.1.xsd 
                 http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.1.xsd
                 http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.1.xsd 
                 http://jboss.com/products/seam/spring http://jboss.com/products/seam/spring-2.1.xsd 
                 http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.1.xsd
                 http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.1.xsd">

	<core:init debug="false" />
	<web:context-filter url-pattern="/dwr/*"/>
	
	<spring:context-loader config-locations="classpath*:META-INF/**/spring/*-context.xml"/>

	<core:manager conversation-timeout="120000"
		concurrent-request-timeout="500" conversation-id-parameter="cid" />

	<transaction:entity-transaction entity-manager="#{em}" />
	<persistence:entity-manager-factory name="wfwcoredatasource" />
	<persistence:managed-persistence-context name="em"
		auto-create="true" entity-manager-factory="#{wfwcoredatasource}" />


	<transaction:entity-transaction name="tt2" entity-manager="#{em2}" />

	<persistence:entity-manager-factory name="wfwcoredatasource2" />
	<persistence:managed-persistence-context name="em2"
		auto-create="true" entity-manager-factory="#{wfwcoredatasource2}" />
			
	<component name="org.jboss.seam.navigation.pages">
		<property name="resources">
			<value>/WEB-INF/pages.xml</value>
			<value>META-INF/wfwdemo/wfwdemo_pages.xml</value>
			<value>META-INF/wfwcore/wfwcore_pages.xml</value>
			<value>META-INF/wfwapp1/wfwapp1_pages.xml</value>
		</property>
	</component>
	<!--  
		<web:logging-filter url-pattern="*.seam" />
		<security:identity
		authenticate-method="#{authenticator.authenticate}" />	 
	-->
	<bpm:jbpm />

	<!--  customization -->
	<component name="com.talgroup.sandbox.seam.configuration">
		<property name="loginPage">
			/pages/wfwcore/login1.xhtml
		</property>
		<property name="mainPage">
			/pages/wfwdemo/mainpage.xhtml
		</property>
	</component>

    <component name="skinBean"
              scope="session"
              class="com.talgroup.wfw.wfwcore.web.ui.SkinBean">
        <property name="skinNames">
        WfwSkin,blueSky,plain,emeraldTown,wine,japanCherry,ruby,classic,deepMarine
        </property>
    </component>

	<component class="org.jboss.seam.web.MultipartFilter">
		<property name="createTempFiles">true</property>
		<property name="maxRequestSize">4000000</property>
	</component>
	<mail:mail-session host="smtp.freeborders.com" port="25" username="acen.chen@freeborders.com" password="19850802"/>
	
</components>

 蓝色字体就是配置数据源的位置

2 配饰persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
	version="1.0">

	<persistence-unit name="wfwcoredatasource"
		transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>
			java:comp/env/jdbc/wfwdemo1_ds
		</jta-data-source>
		<class>com.talgroup.wfw.wfwcore.app.domain.User</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Configuration</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Profile</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Function</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Role</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Group</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.UserGroup</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.RoleGroup</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.UserLockInfo</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.ADServerInfo</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.ConfigParameter</class>		
		<class>com.talgroup.wfw.wfwcore.app.domain.LoginUserInfo</class>
		
		<class>com.talgroup.wfw.wfwdemo.jpa.Hotel</class>
		<class>com.talgroup.wfw.wfwdemo.persistent.Tag</class>
		
		
		<properties>

			<!--  <property name="hibernate.hbm2ddl.auto" value="create-drop" /> -->
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.dialect"
				value="com.talgroup.wfw.wfwcore.app.services.persistentService.DB2Dialect" />
			<property name="hibernate.cache.provider_class"
				value="org.hibernate.cache.HashtableCacheProvider" />

			<property name="hibernate.cache.provider_class"
				value="org.hibernate.cache.HashtableCacheProvider" />
			<!-- RESOURCE_LOCAL
				<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
			-->
			<!-- alternative
				<property name="jboss.entity.manager.factory.jndi.name" 
				value="java:/jpaBookingEntityManagerFactory"/>
			-->
		</properties>
	</persistence-unit>
	<persistence-unit name="wfwcoredatasource2"
		transaction-type="RESOURCE_LOCAL">
		<provider>org.hibernate.ejb.HibernatePersistence</provider>
		<jta-data-source>
			java:comp/env/jdbc/wfwdemo2_ds
		</jta-data-source>
		<class>com.talgroup.wfw.wfwcore.app.domain.User</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Configuration</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Profile</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Function</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Role</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.Group</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.UserGroup</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.RoleGroup</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.UserLockInfo</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.ADServerInfo</class>
		<class>com.talgroup.wfw.wfwcore.app.domain.ConfigParameter</class>		
		<class>com.talgroup.wfw.wfwcore.app.domain.LoginUserInfo</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Hotel</class>
		<class>com.talgroup.wfw.wfwdemo.persistent.Tag</class>

				
		<class>com.talgroup.wfw.wfwdemo.jpa.Hotel</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Booking</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Publisher</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.PubInfo</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Author</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Title</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.Book</class>
		<class>com.talgroup.wfw.wfwdemo.jpa.SimpleObject</class>

		<properties>
			<!-- 
				<property name="hibernate.hbm2ddl.auto" value="update" />
			-->
			<property name="hibernate.show_sql" value="true" />
			<property name="hibernate.dialect"
				value="com.talgroup.wfw.wfwcore.app.services.persistentService.DB2Dialect" />
			<property name="hibernate.cache.provider_class"
				value="org.hibernate.cache.HashtableCacheProvider" />

			<property name="hibernate.cache.provider_class"
				value="org.hibernate.cache.HashtableCacheProvider" />
			<!-- RESOURCE_LOCAL
				<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
			-->
			<!-- alternative
				<property name="jboss.entity.manager.factory.jndi.name" 
				value="java:/jpaBookingEntityManagerFactory"/>
			-->
		</properties>
	</persistence-unit>


</persistence>

 

论坛首页 编程语言技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics