[SEAM] 请教 一个项目同时连接2个数据库,怎样连接?

eosite 2009-06-03
创建2个 EntityManager,是怎样配置的~
andyhan 2009-06-03
在components.xml里面声明EntityManager,最好默认的entityManager还是用entityManager这个名字,seam内置的一些外围组件用的这个名字。
persistence.xml里面连接不同的datasource。
eosite 2009-06-03
components.xml
<persistence:managed-persistence-context name="entityManager" auto-create="true" persistence-unit-jndi-name="java:/AISEntityManagerFactory"/>
   
<persistence:managed-persistence-context name="entityManagerForeTV" auto-create="true" persistence-unit-jndi-name="java:/ForeTVEntityManagerFactory"/>


persistence-dev.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- Persistence deployment descriptor for dev profile -->
<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="AIS">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/AISDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/AISEntityManagerFactory"/>
      </properties>
   </persistence-unit>
   
   <persistence-unit name="ForeTV">
      <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <jta-data-source>java:/ForeTVDatasource</jta-data-source>
      <properties>
         <property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
         <property name="hibernate.show_sql" value="true"/>
         <property name="hibernate.format_sql" value="true"/>
         <property name="jboss.entity.manager.factory.jndi.name" value="java:/ForeTVEntityManagerFactory"/>
      </properties>
   </persistence-unit>
</persistence>


AIS-dev-ds.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE datasources
    PUBLIC "-//JBoss//DTD JBOSS JCA Config 1.5//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-ds_1_5.dtd">
    
<datasources>
   
   <local-tx-datasource>
      <jndi-name>AISDatasource</jndi-name>
      <connection-url>jdbc:sqlserver://localhost:1433; DatabaseName=NowAMS</connection-url>
      <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
      <user-name>sa</user-name>
      <password>11</password>
   </local-tx-datasource>

    <local-tx-datasource>
      <jndi-name>ForeTVDatasource</jndi-name>
      <connection-url>jdbc:sqlserver://localhost:1433; DatabaseName=eosite</connection-url>
      <driver-class>com.microsoft.sqlserver.jdbc.SQLServerDriver</driver-class>
      <user-name>sa</user-name>
      <password>11</password>
   </local-tx-datasource>
    
</datasources>


action类
@PersistenceContext(unitName = "AIS")
private EntityManager em;

@PersistenceContext(unitName = "ForeTV")
private EntityManager em1;


主要的配置文件是这些~ 运行报错
org.jboss.resource.connectionmanager.JBossLocalXAException: Trying to start a new tx when old is not complete

Could not enlist in transaction on entering meta-aware object!

org.hibernate.exception.GenericJDBCException: Cannot open connection

问题似乎是事务没结束,就开始新的~ 有了解这方面的吗?请指教
ywbanm 2009-06-04
private  这个去掉试试
ywbanm 2009-06-04
我这用JBoss4.2.3配了2个数据源的,没有这个问题。
5day 2009-06-04
不用XA直接用TX可以吗?
5day 2009-06-04
映像中必须用XA的datasource哦?
Mrpublic 2009-06-16
5day XA 是啥東西,我要充電。。。謝謝
Global site tag (gtag.js) - Google Analytics