Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

Siddhesh Kenkre

Greenhorn
+ Follow
since Jan 02, 2013
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Siddhesh Kenkre

Hello all ,
I am not creating the entityManager in the JSF managed bean. I create it in the service class and and all the DB operations are done here in the service class.
Hello All,
I m new to JSF and primefaces... I m currently working on a JSF project with primefaces wherein i have to access 2 databases A and B . I have create 2 persistent units in persistence.xml as follows

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
<persistence-unit name="myJSFAppPU" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>java:/LnpDatasource</non-jta-data-source>
<class>com.proj.entity.table1</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://192.168.5.228:3306/A"/>
<property name="hibernate.connection.username" value="lsms_yogesh"/>
<property name="hibernate.connection.password" value="hello09"/>
</properties>
</persistence-unit>

<persistence-unit name="myJSFAppPU1" transaction-type="RESOURCE_LOCAL">
<non-jta-data-source>java:/LnpDatasource_NE</non-jta-data-source>
<class>com.proj.entity.table2</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
<property name="hibernate.connection.url" value="jdbc:mysql://192.168.5.228:3306/B"/>
<property name="hibernate.connection.username" value="lsms_shango_test"/>
<property name="hibernate.connection.password" value="hello09"/>
</properties>
</persistence-unit>
</persistence>

My datasource files i have kept in deploy folder of jboss server

Contents of my -ds files
Filename : LnpDatasource-ds.xml
<datasources>
<local-tx-datasource>
<jndi-name>LnpDatasource</jndi-name>
<use-java-context>true</use-java-context>
<connection-url>jdbc:mysql://192.168.5.228:3306/A</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>lsms_yogesh</user-name>
<password>hello09</password>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

Filename : LnpDatasource_NE-ds.xml


<datasources>
<local-tx-datasource>
<jndi-name>LnpDatasource_NE</jndi-name>
<use-java-context>true</use-java-context>
<connection-url>jdbc:mysql://192.168.5.228:3306/B</connection-url>
<driver-class>com.mysql.jdbc.Driver</driver-class>
<user-name>lsms_shango_test</user-name>
<password>hello09</password>
<metadata>
<type-mapping>mySQL</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>

My queries:

1) is it OK for me to use <non-jta-data-source> ? Shud i change to <jta-data-source> ?
2) Is the content of -ds.xml files correct ?
3) I have created 2 entityManagers( em1 and em2 ) one for each persistent unit. and am using the annotation @PersistenceContext(unitName = "") before my entityManager declaration. In my case when i first use em1 and then try to fire a query using em2 , the query does not get fired and i get "javax.faces.el.EvaluationException: java.lang.IllegalStateException: Transaction not active" error. How to solve this ?
4) Do i have to add any separate configuration file to my project ... During googling i came across one post when it says we have to add "applicationContext.xml" file to our project.