You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@openjpa.apache.org by SreeAsh <sr...@fs.mphasis.com> on 2010/05/11 14:52:44 UTC

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-EntittyManager-Taking-4-seconds-tp5035800p5035800.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.

Re: Get the persistencUnit using EntittyManager Taking 4 seconds

Posted by Daryl Stultz <da...@opentempo.com>.
On Tue, May 11, 2010 at 9:12 AM, C N Davies <cn...@cndavies.com> wrote:

> 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.


Hmm, I'm not sure I buy that. The OP's code does not clearly indicate where
the 4 seconds of processing is occurring. I can see the EMF taking 4 seconds
to instantiate.


> The only solution I have found is to keep an EM hanging around as
> long as possible and reuse it,


I create and throw away an EM with each HTTP request. I don't have any
performance problems with this.

-- 
Daryl Stultz
_____________________________________
6 Degrees Software and Consulting, Inc.
http://www.6degrees.com
http://www.opentempo.com
mailto:daryl.stultz@opentempo.com

RE: Get the persistencUnit using EntittyManager Taking 4 seconds

Posted by C N Davies <cn...@cndavies.com>.
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:srinivasulu.kristnam@fs.mphasis.com] 
Sent: Tuesday, 11 May 2010 10:53 PM
To: users@openjpa.apache.org
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.


Re: Get the persistencUnit using EntittyManager Taking 4 seconds

Posted by Donald Woods <dw...@apache.org>.
Do you really need the following in your persistence.xml?
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
Listing all of your entity classes and then setting it to true along
with adding
    <properties>
        <property name="openjpa.DynamicEnhancementAgent"
            value="true"/>
    </properties>
which turns off dynamic enhancement (which means you have to use build
time enhancement) may help your speed issue (without more profiling data
to go on....)


-Donald


On 5/11/10 8:52 AM, SreeAsh wrote:
> 
> 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>
>