This is one of the significant limitations with JPA, not just OpenJPA, each
time you create an entity manager it reads all the DB meta before you can do
anything. The only solution I have found is to keep an EM hanging around as
long as possible and reuse it, this has it's own problems since it's single
threaded. I found the best solution was to buy a thumping great DB server to
speed things up while we develop our own persistence layer. 

Build time enhancement does seems to improve things though. EJB 2 also does
:) 


Chris



-----Original Message-----
From: SreeAsh [mailto:[email protected]] 
Sent: Tuesday, 11 May 2010 10:53 PM
To: [email protected]
Subject: Get the persistencUnit using EntittyManager Taking 4 seconds


Hi 

 I am using the following code to get the persistenceUnit, but taking 4
seconds to connect can i reduce the same.please find the below code

 public static EntityManager getSQLEM() {
        try {
            if (em == null) {
                emf =
Persistence.createEntityManagerFactory(ConstantUtil.SQLSERVER_PERSISIT_UNIT)
;
                em = emf.createEntityManager();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return em;
    }

and i have the persistence xml like this 
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.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_1_0.xsd";>

  <!--SQl Server Persistence Unit-->
  <persistence-unit name="CRMSQL" transaction-type="RESOURCE_LOCAL">
   
<provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider>
 
    <class>com.epoint.entity.common.UserInformation</class>
    <class>com.epoint.entity.common.ProductUserRole</class>
    <class>com.epoint.entity.common.ProductRoleObject</class>
    <class>com.epoint.entity.common.ProductObject</class>
    <class>com.epoint.entity.common.AccessLookup</class>
    <class>com.epoint.entity.common.CompoundKeyAccessLookup</class>

    <!--Srini Added-->
     <class>com.epoint.entity.campaign.Campaign</class>
    
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
      <property name="openjpa.ConnectionUserName" value="sa"/>
      <property name="openjpa.ConnectionPassword" value="password"/>
      <property name="openjpa.ConnectionURL"
value="jdbc:sqlserver://host:port;databaseName=test"/>
      <property name="openjpa.ConnectionDriverName"
value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
      <property name="openjpa.jdbc.Schema" value="dbo"/>
      <!--<property name="openjpa.Log" value="DefaultLevel=ERROR,
SQL=TRACE"/>-->
    </properties>
  </persistence-unit>
  <!--SQl Server Persistence Unit End-->

</persistence>

-- 
View this message in context:
http://openjpa.208410.n2.nabble.com/Get-the-persistencUnit-using-EntittyMana
ger-Taking-4-seconds-tp5035800p5035800.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Reply via email to