How to specify more than one persistence context in Componen
gsawant Feb 5, 2008 6:19 PMHi
I am working on Seam 2.0 pojo, toplink, tomcat6. I got it working with one persistence unit where my components.xml and persistence.xml and context.xml file looked like below
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:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.0.xsd http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd"> <core:init debug="true" /> <core:manager conversation-timeout="120000" /> <transaction:entity-transaction entity-manager="#{em}" /> <persistence:entity-manager-factory name="helloworld" /> <persistence:managed-persistence-context name="em" auto-create="true" entity-manager-factory="#{helloworld}" /> </components>
persistence.xml file
<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 persistence_1_0.xsd" version="1.0"> <persistence-unit name="helloworld" transaction-type="RESOURCE_LOCAL"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <non-jta-data-source>java:comp/env/jdbc/PortalDS</non-jta-data-source> <class>Person</class> <properties> <property name="toplink.logging.level" value="FINE"/> <!-- <property name="toplink.ddl-generation" value="drop-and-create-tables"/> --> <property name="toplink.session.customizer" value="ToplinkSessionCustomizer"/> </properties> </persistence-unit> </persistence>
context.xml
<Context path="/tomcatoratoplink" docBase="tomcatoratoplink" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/PortalDS" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="ghxmonitor_040200" password="ghxmonitor" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@devdb10.ghx.com:1526:devdb1"/>
Now I made changes to persistence.xml and context .xml file to add one more persistence unit as follows
persistence.xml
<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 persistence_1_0.xsd" version="1.0"> <persistence-unit name="helloworld" transaction-type="RESOURCE_LOCAL"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <non-jta-data-source>java:comp/env/jdbc/PortalDS</non-jta-data-source> <class>Person</class> <properties> <property name="toplink.logging.level" value="FINE"/> <!-- <property name="toplink.ddl-generation" value="drop-and-create-tables"/> --> <property name="toplink.session.customizer" value="ToplinkSessionCustomizer"/> </properties> </persistence-unit> <persistence-unit name="Registration" transaction-type="RESOURCE_LOCAL"> <provider>oracle.toplink.essentials.PersistenceProvider</provider> <non-jta-data-source>java:comp/env/jdbc/SFRegistration</non-jta-data-source> <properties> <property name="toplink.logging.level" value="FINE"/> <property name="toplink.session.customizer" value="ToplinkSessionCustomizer"/> </properties> </persistence-unit> </persistence>
context.xml
<Context path="/tomcatoratoplink" docBase="tomcatoratoplink" debug="5" reloadable="true" crossContext="true"> <Resource name="jdbc/PortalDS" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="ghxmonitor_040200" password="ghxmonitor" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@devdb10.ghx.com:1526:devdb1"/> <Resource name="jdbc/SFRegistration" auth="Container" type="javax.sql.DataSource" maxActive="100" maxIdle="30" maxWait="10000" username="reg_api" password="reg_api_pwd" driverClassName="oracle.jdbc.OracleDriver" url="jdbc:oracle:thin:@devdb10.ghx.com:1527:devdb1"/> </Context>
but I don't know how to specify another entity manager in components.xml for persistence unit "Registration".
Any help appreciated.
Thanks
Geeta