5

Address has many-to-one relationship with person like :

Person :

@Id 
    @Column(name="personid")
    private Long personId;
    private String firstName;
    private String lastName;
    private String email;    

    @OneToMany(cascade = CascadeType.ALL,mappedBy="person",targetEntity=Address.class,fetch=FetchType.LAZY)      
    private List addressArray=new ArrayList<>();   
    public Person() {

    }  

and Address :

@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="personId")
    private Person person;

I want to access person's firstname from the address object like "address.person.firstname" but it always eager load the person ?

I also tried to static weave it using maven my pom.xml contains :

<plugins>
        <artifactId>maven-antrun-plugin</artifactId>
     <executions>
       <execution>
         <phase>process-classes</phase>
         <configuration>
           <tasks>
             <java classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeave"
                   classpathref="maven.runtime.classpath" fork="true">
               <arg line="-loglevel FINE -persistenceinfo src target/classes target/classes"/>
             </java>
           </tasks>
         </configuration>
         <goals>
           <goal>run</goal>
         </goals>
       </execution>
     </executions>
      </plugin>

        </plugins>

also added <property name="eclipselink.weaving" value="static"/> in persistence.xml

I also tried dynamic weaving but it gives exception :

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:382)
    at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:397)
Caused by: java.lang.NoClassDefFoundError: javax/persistence/spi/PersistenceUnitInfo
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:186)
    at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.initializeFromAgent(JavaSECMPInitializerAgent.java:44)
    at org.eclipse.persistence.internal.jpa.deployment.JavaSECMPInitializerAgent.premain(JavaSECMPInitializerAgent.java:39)
    ... 6 more
Caused by: java.lang.ClassNotFoundException: javax.persistence.spi.PersistenceUnitInfo
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    ... 10 more
FATAL ERROR in native method: processing of -javaagent failed
Exception in thread "main" 

My static woven class files show following methods but still does not work :

enter image description here

Please check my log after weaving when weaving=static and logging = FINEST

[EL Finest]: jpa: 2013-09-26 18:07:40.453--ServerSession(8941730)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Initial; factoryCount 0
[EL Finest]: properties: 2013-09-26 18:07:40.475--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.orm.throw.exceptions; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.475--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.changetracking; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.476--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.lazy; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.476--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.eager; default value=false
[EL Finest]: properties: 2013-09-26 18:07:40.476--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.fetchgroups; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.476--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.internal; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.476--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.weaving.rest; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.477--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.multitenant.tenants-share-emf; default value=true
[EL Finest]: properties: 2013-09-26 18:07:40.478--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.multitenant.tenants-share-cache; default value=false
[EL Finer]: metadata: 2013-09-26 18:07:40.496--ServerSession(8941730)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/ (There is no English translation for this message.)
[EL Finer]: metadata: 2013-09-26 18:07:40.5--ServerSession(8941730)--Thread(Thread[main,5,main])--Searching for default mapping file in file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/ (There is no English translation for this message.)
[EL Config]: metadata: 2013-09-26 18:07:40.681--ServerSession(8941730)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.altametrics.persistence.services.Address] is set to [FIELD].
[EL Config]: metadata: 2013-09-26 18:07:40.723--ServerSession(8941730)--Thread(Thread[main,5,main])--The target entity (reference) class for the many to one mapping element [field person] is being defaulted to: class com.altametrics.persistence.services.Person.
[EL Config]: metadata: 2013-09-26 18:07:40.725--ServerSession(8941730)--Thread(Thread[main,5,main])--The access type for the persistent class [class com.altametrics.persistence.services.Person] is set to [FIELD].
[EL Config]: metadata: 2013-09-26 18:07:40.733--ServerSession(8941730)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.altametrics.persistence.services.Address] is being defaulted to: Address.
[EL Config]: metadata: 2013-09-26 18:07:40.735--ServerSession(8941730)--Thread(Thread[main,5,main])--The table name for entity [class com.altametrics.persistence.services.Address] is being defaulted to: ADDRESS.
[EL Config]: metadata: 2013-09-26 18:07:40.759--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [id] is being defaulted to: ID.
[EL Config]: metadata: 2013-09-26 18:07:40.761--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [addressLine2] is being defaulted to: ADDRESSLINE2.
[EL Config]: metadata: 2013-09-26 18:07:40.762--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [addressLine1] is being defaulted to: ADDRESSLINE1.
[EL Config]: metadata: 2013-09-26 18:07:40.762--ServerSession(8941730)--Thread(Thread[main,5,main])--The alias name for the entity class [class com.altametrics.persistence.services.Person] is being defaulted to: Person.
[EL Config]: metadata: 2013-09-26 18:07:40.762--ServerSession(8941730)--Thread(Thread[main,5,main])--The table name for entity [class com.altametrics.persistence.services.Person] is being defaulted to: PERSON.
[EL Config]: metadata: 2013-09-26 18:07:40.763--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [id] is being defaulted to: ID.
[EL Config]: metadata: 2013-09-26 18:07:40.763--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [lastName] is being defaulted to: LASTNAME.
[EL Config]: metadata: 2013-09-26 18:07:40.763--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [email] is being defaulted to: EMAIL.
[EL Config]: metadata: 2013-09-26 18:07:40.764--ServerSession(8941730)--Thread(Thread[main,5,main])--The column name for element [firstName] is being defaulted to: FIRSTNAME.
[EL Config]: metadata: 2013-09-26 18:07:40.785--ServerSession(8941730)--Thread(Thread[main,5,main])--The primary key column name for the mapping element [field person] is being defaulted to: ID.
[EL Finer]: weaver: 2013-09-26 18:07:40.805--ServerSession(8941730)--Thread(Thread[main,5,main])--Class [com.altametrics.persistence.services.Address] registered to be processed by weaver.
[EL Finer]: weaver: 2013-09-26 18:07:40.807--ServerSession(8941730)--Thread(Thread[main,5,main])--Class [com.altametrics.persistence.services.Person] registered to be processed by weaver.
[EL Finest]: jpa: 2013-09-26 18:07:40.809--ServerSession(8941730)--Thread(Thread[main,5,main])--End predeploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Predeployed; factoryCount 0
[EL Finer]: weaver: 2013-09-26 18:07:40.81--Thread(Thread[main,5,main])--JavaSECMPInitializer - transformer is null.
[EL Finest]: jpa: 2013-09-26 18:07:40.81--ServerSession(8941730)--Thread(Thread[main,5,main])--Begin predeploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Predeployed; factoryCount 0
[EL Finest]: jpa: 2013-09-26 18:07:40.81--ServerSession(8941730)--Thread(Thread[main,5,main])--End predeploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Predeployed; factoryCount 1
[EL Finest]: jpa: 2013-09-26 18:07:40.815--ServerSession(8941730)--Thread(Thread[main,5,main])--Begin deploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Predeployed; factoryCount 1
[EL Finer]: 2013-09-26 18:07:40.829--ServerSession(8941730)--Thread(Thread[main,5,main])--Could not initialize Validation Factory. Encountered following exception: java.lang.NoClassDefFoundError: javax/validation/Validation
[EL Finest]: properties: 2013-09-26 18:07:40.831--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: properties: 2013-09-26 18:07:40.832--ServerSession(8941730)--Thread(Thread[main,5,main])--property=eclipselink.logging.level; value=FINEST; translated value=FINEST
[EL Finest]: properties: 2013-09-26 18:07:40.837--ServerSession(8941730)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.user; value=root
[EL Finest]: properties: 2013-09-26 18:07:40.837--ServerSession(8941730)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.password; value=xxxxxx
[EL Finest]: properties: 2013-09-26 18:07:41.502--ServerSession(8941730)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.driver; value=com.mysql.jdbc.Driver
[EL Finest]: properties: 2013-09-26 18:07:41.502--ServerSession(8941730)--Thread(Thread[main,5,main])--property=javax.persistence.jdbc.url; value=jdbc:mysql://localhost:3306/sample
[EL Info]: 2013-09-26 18:07:41.506--ServerSession(8941730)--Thread(Thread[main,5,main])--EclipseLink, version: Eclipse Persistence Services - 2.5.0.v20130507-3faac2b
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.757--Thread(Thread[main,5,main])--(?i)oracle.*12 (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.757--Thread(Thread[main,5,main])--(?i)oracle.*11 (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.757--Thread(Thread[main,5,main])--(?i)oracle.*10 (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.758--Thread(Thread[main,5,main])--(?i)oracle.*9 (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.758--Thread(Thread[main,5,main])--(?i)oracle.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.758--Thread(Thread[main,5,main])--SQL\ Anywhere.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.758--Thread(Thread[main,5,main])--(?i)(sybase.*)|(adaptive\ server\ enterprise.*)|(SQL\ Server.*) (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.759--Thread(Thread[main,5,main])--(?i)microsoft.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.759--Thread(Thread[main,5,main])--(?i).*derby.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.759--Thread(Thread[main,5,main])--(?i).*db2.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.759--Thread(Thread[main,5,main])--(?i)pointbase.* (There is no English translation for this message.)
[EL Finest]: dbPlatformHelper_regExprDbPlatform: 2013-09-26 18:07:41.759--Thread(Thread[main,5,main])--(?i)mysql.* (There is no English translation for this message.)
[EL Fine]: connection: 2013-09-26 18:07:41.76--Thread(Thread[main,5,main])--Detected database platform: org.eclipse.persistence.platform.database.MySQLPlatform
[EL Config]: connection: 2013-09-26 18:07:41.771--ServerSession(8941730)--Connection(7521179)--Thread(Thread[main,5,main])--connecting(DatabaseLogin(
    platform=>MySQLPlatform
    user name=> "root"
    datasource URL=> "jdbc:mysql://localhost:3306/sample"
))
[EL Config]: connection: 2013-09-26 18:07:41.783--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connected: jdbc:mysql://localhost:3306/sample
    User: root@localhost
    Database: MySQL  Version: 5.1.39-community
    Driver: MySQL-AB JDBC Driver  Version: mysql-connector-java-5.1.18 ( Revision: tonci.grgin@oracle.com-20110930151701-jfj14ddfq48ifkfq )
[EL Finest]: connection: 2013-09-26 18:07:41.783--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Finest]: connection: 2013-09-26 18:07:41.783--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Info]: connection: 2013-09-26 18:07:41.828--ServerSession(8941730)--Thread(Thread[main,5,main])--file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB login successful
[EL Finer]: metamodel: 2013-09-26 18:07:41.841--ServerSession(8941730)--Thread(Thread[main,5,main])--Canonical Metamodel class [com.altametrics.persistence.services.Person_] not found during initialization.
[EL Finer]: metamodel: 2013-09-26 18:07:41.842--ServerSession(8941730)--Thread(Thread[main,5,main])--Canonical Metamodel class [com.altametrics.persistence.services.Address_] not found during initialization.
[EL Finest]: jpa: 2013-09-26 18:07:41.842--ServerSession(8941730)--Thread(Thread[main,5,main])--End deploying Persistence Unit TestDB; session file:/C:/Users/achyut_anr/achyut_anr/CheckWeaving/bin/_TestDB; state Deployed; factoryCount 1
[EL Finer]: connection: 2013-09-26 18:07:41.863--ServerSession(8941730)--Thread(Thread[main,5,main])--client acquired: 3812334
[EL Finer]: transaction: 2013-09-26 18:07:41.872--ClientSession(3812334)--Thread(Thread[main,5,main])--acquire unit of work: 25692210
[EL Finest]: query: 2013-09-26 18:07:41.887--UnitOfWork(25692210)--Thread(Thread[main,5,main])--Execute query ReadObjectQuery(name="readAddress" referenceClass=Address sql="SELECT ID, ADDRESSLINE1, ADDRESSLINE2, personid FROM ADDRESS WHERE (ID = ?)")
[EL Finest]: connection: 2013-09-26 18:07:41.889--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: sql: 2013-09-26 18:07:41.889--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--SELECT ID, ADDRESSLINE1, ADDRESSLINE2, personid FROM ADDRESS WHERE (ID = ?)
    bind => [1]
[EL Finest]: connection: 2013-09-26 18:07:41.913--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: query: 2013-09-26 18:07:41.917--ServerSession(8941730)--Thread(Thread[main,5,main])--Execute query ReadObjectQuery(name="person" referenceClass=Person )
[EL Finest]: connection: 2013-09-26 18:07:41.917--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection acquired from connection pool [default].
[EL Fine]: sql: 2013-09-26 18:07:41.918--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--SELECT ID, EMAIL, FIRSTNAME, LASTNAME FROM PERSON WHERE (ID = ?)
    bind => [1]
[EL Finest]: connection: 2013-09-26 18:07:41.919--ServerSession(8941730)--Connection(27722152)--Thread(Thread[main,5,main])--Connection released to connection pool [default].
[EL Finest]: transaction: 2013-09-26 18:07:41.922--UnitOfWork(25692210)--Thread(Thread[main,5,main])--Register the existing object  personId=1

My persistence unit looks like :

 <persistence-unit name="TestDB">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>com.altametrics.persistence.services.Person</class>      
        <class>com.altametrics.persistence.services.Address</class>
         <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>          

            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/sample"/>
            <property name="javax.persistence.jdbc.password" value="admin"/>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver"/>
            <property name="javax.persistence.jdbc.user" value="root"/> 
            <property name="eclipselink.weaving" value="static"/>         
            <!--  <property name="eclipselink.ddl-generation" value="drop-and-create-tables" /> -->
          <property name="eclipselink.logging.level" value="FINEST"/> 

        </properties>
    </persistence-unit>
Achyut
  • 377
  • 1
  • 3
  • 17
  • Have you setup weaving? EclipseLink lazy on ManyToOne and OneToone requires the use of byte code weaving http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving If you are accessing the person, how are you determining that it wasn't lazily loaded - the act of accessing the relationship will cause it to be fetched. – Chris Sep 11 '13 at 16:19
  • @Chris thanks! If person has other relationships like with department or city it logs the query for person as well as find city and department also – Achyut Sep 11 '13 at 16:39
  • 1
    Check out the link for dynamic weaving and weaving in Java EE servers. If this isn't in a Java EE server, you will have to setup dynamic weaving with an agent, or use static weaving options. – Chris Sep 11 '13 at 17:35
  • @Chris but it works for one to many fetching. Is Iam doing something wrong ? – Achyut Sep 12 '13 at 12:58
  • Yes it should always work for collection type mappings as they do not require weaving - a proxy collection can be used. Weaving is used for lazy 1:1, M:1, fetch groups, change tracking and other performance enhancements. – Chris Sep 12 '13 at 13:47
  • @Chris Iam using simple persistence application then how to weave it ? – Achyut Sep 12 '13 at 13:51
  • Follow one of the options presented in the link - static weaving or dynamic using an agent. – Chris Sep 12 '13 at 14:01
  • @Chris thanks! but I set the property eclipselink.weaving to static in persistence.xml but there is no effect. – Achyut Sep 12 '13 at 14:04
  • You need to actually run the static weaver on your class files, and then use the newly generated class files in your application in addition to specifying that they were statically woven in your persistence.xml. This changes the bytes within your entities to support lazy relationships. – Chris Sep 12 '13 at 14:06
  • @Chris I added the new class files (please see above edits) but still showing eager loading behaviour . Did I missed something ? Please help – Achyut Sep 19 '13 at 13:08

1 Answers1

5

weaving is required for some lazy relationships and enabling other performance enhancements in EclipseLink such as fetch groups and change tracking, as described at http://www.eclipse.org/eclipselink/documentation/2.4/concepts/app_dev007.htm

Weaving is generally automatic occurs within EE 7 containers, but will require work outside of the container or in non-EE7 containers. So to get lazy to work on 1:1 and M:1, you will need to enable weaving either dynamically through use of an agent, or statically weaving class files and then using those.

Chris
  • 20,138
  • 2
  • 29
  • 43
  • I used dynamic weaving but it gives error :Error occurred during initialization of VM agent library failed to init: instrument Error opening zip file or JAR manifest missing : eclipselink-2.5.0.jar – Achyut Sep 12 '13 at 14:24
  • What did you use to setup the agent, and does the jar exist in that location? – Chris Sep 12 '13 at 19:27
  • I did static weaving using maven please check my edits to question – Achyut Sep 13 '13 at 08:10
  • Did you check that the classfiles were actually modified, and that you are using them in your application? What happened with the dynamic weaving attempt? – Chris Sep 13 '13 at 15:12
  • The dynamic weaving issue is caused because you do not have the persistence.jar on your classpath. The persistence.jar contains the JPA spec classes required to use JPA, such as javax.persistence.spi.PersistenceUnitInfo. – Chris Sep 18 '13 at 12:48
  • Thanks for your support! I am able to weaved it statically using maven. But when used that weaved classes to another project it is not performing lazy loading.Iam frustated.Please help. – Achyut Sep 18 '13 at 16:06
  • What do you mean it is eagerly loading now? When you access address.getPerson(), this will force the person relation to get fetched. So how are you accessing it and seeing that lazy isn't being respected? – Chris Sep 19 '13 at 14:03
  • no Iam only accessing address by primary key ,I set logging level FINE and found it queried for both address and person .[EL Fine]: sql: 2013-09-19 19:14:39.451--ServerSession(2906128)--Connection(20118148)--Thread(Thread[main,5,main])--SELECT ID, ADDRESSLINE1, ADDRESSLINE2, personid FROM ADDRESS WHERE (ID = ?) bind => [1] [EL Fine]: sql: 2013-09-19 19:14:39.477--ServerSession(2906128)--Connection(20118148)--Thread(Thread[main,5,main])--SELECT ID, EMAIL, FIRSTNAME, LASTNAME FROM PERSON WHERE (ID = ?) bind => [1] – Achyut Sep 19 '13 at 14:29
  • Did you add in the eclipselink.weaving property to specify that you used static weaving? If so, set logging to finest and check the logs for indications as to what is going wrong – Chris Sep 20 '13 at 13:25
  • I am done with the eclipselink.weaving property and also set level to finest. It executes normally but doesn't show any error or warning in log. – Achyut Sep 24 '13 at 10:18
  • There should be a whole lot of information printed in the logs as it processes each mapping on each entity, one of which should point to why it is using eager instead of lazy. Check both the log from static weaving as well as deployment. – Chris Sep 24 '13 at 12:42
  • it gives Canonical Metamodel class [com.altametrics.persistence.services.Address_] not found during initialization. – Achyut Sep 24 '13 at 13:50
  • Is the full Address class? Check there aren't any toString or postLoad type methods that might access lazy references that are getting called. Change the relationship in Person so that it points to a non-existent field and will throw an exception when the query executes, and post the stack trace to see what is causing the query. – Chris Sep 26 '13 at 14:59
  • no sir, I checked both person and address they don't have any toString() or postLoad methods. Please elaborate your second statement .Thanks! – Achyut Sep 27 '13 at 16:39
  • if I don't include the entities in my persistence unit (please see my edits) It gives an error of "Unknown entity bean class" . Why ? if I had entity classes in my jar file ? – Achyut Sep 30 '13 at 13:19
  • You should create a new question with your current state, as I believe it is too long for anyone else to follow what you are doing at this point. Figure out what is causing the extra query by simply removing a field from the database from Person, so that any query on the Person table by JPA would cause an exception. The code you've shown will then run up until Person is queried on, and show you why it is being queried. Show that, the full Address class and the log and someone might help. The exclude-unlisted-classes tag controls finding entities, and seems like you have classloader issues – Chris Sep 30 '13 at 15:54
  • is it possible to have dynamic weaving while using tomcat web server ? If yes , how ? – Achyut Oct 16 '13 at 10:38