Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » how can i control the persistence.xml file unit name in weblogic server
how can i control the persistence.xml file unit name in weblogic server [message #1118333] Fri, 27 September 2013 09:51
Vijay Kumar is currently offline Vijay KumarFriend
Messages: 6
Registered: May 2013
Junior Member
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.
Previous Topic:Moxy and Reference Impl schemas do not match
Next Topic:Is it possible to define everything for Composite Persistent Units in one persistence.xml ?
Goto Forum:
  


Current Time: Mon Jan 20 03:46:21 GMT 2025

Powered by FUDForum. Page generated in 0.04085 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top