Hi,
I am using multipule data source for one of my project. these data sources will hit 2 different data base schema s.
<persistence-unit name="UnitRead" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/READ</jta-data-source>
<class>org.model.Employee</class>
<class>org.model.Department</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10" />
<!-- Logging level is set to INFO, Need to change in Production -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
property name="eclipselink.persistence-context.close-on-commit" value="true" />
<property name="eclipselink.cache.shared.default" value="false" />
</properties>
</persistence-unit>
<persistence-unit name="UnitWRITE" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>jdbc/WRITE</jta-data-source>
<class>org.model.Employee</class>
<class>org.model.Department</class>
<exclude-unlisted-classes>true</exclude-unlisted-classes>
<properties>
<property name="eclipselink.target-server" value="WebLogic_10" />
<!-- Logging level is set to INFO, Need to change in Production -->
<property name="eclipselink.logging.level" value="FINE" />
<property name="eclipselink.persistence-context.flush-mode" value="COMMIT" />
property name="eclipselink.persistence-context.close-on-commit" value="true" />
<property name="eclipselink.cache.shared.default" value="false" />
</properties>
</persistence-unit>
It is straight forward and it is working.but problem came in as environment. i came to know that one server will have only single data source for both read and write.I am using web logic server. in that scenario i will not have 2 data sources defined in web logic server. it is throwing an error since my persistence has 2 units.
I have 2 quick quesitions here.
first one,if i define both data sources in perssitence.xml file how can i avoid the server to skip the error if there is no data source defined.
second, can i able to control this dynamically? any sample code available.
for this i have tried following
public EntityManager getEntityManager() {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("UnitRead",createDataSourceProerties());
entityManager = emf.createEntityManager();
return this.entityManager;
}
public static Map<String, String> createDataSourceProerties(){
Map<String,String> dataSourceProerties = new HashMap<String,String>();
dataSourceProerties.put("TRANSACTION_TYPE",PersistenceUnitTransactionType.JTA.name();
dataSourceProerties.put("eclipselink.target-server","WebLogic_10");
dataSourceProerties.put("eclipselink.logging.level","FINE");
dataSourceProerties.put("eclipselink.persistence-context.flush-mode","commit");
dataSourceProerties.put("eclipselink.persistence-context.close-on-commit","false");
dataSourceProerties.put("eclipselink.cache.shared.default","true");
dataSourceProerties.put("JDBC_DRIVER", "oracle.jdbc.OracleDriver");
dataSourceProerties.put("JDBC_URL", "jdbc:oracle:thin:@localhost:1521:xe");
dataSourceProerties.put("JDBC_USER", "user");
dataSourceProerties.put("JDBC_PASSWORD", "user");
return dataSourceProerties;
}
but this is throwing null pointer exception.
Looking for some valuable tips.