How to enable weaving in EclipseLink?

大城市里の小女人 提交于 2019-12-11 07:46:41

问题


I receive the following warning on the GlassFish terminal while deploying an application that has lazy fetching in entities,

WARNING: Reverting the lazy setting on the OneToOne or ManyToOne attribute [zoneTable] for the entity class [class entity.ZoneCharge] since weaving was not enabled or did not occur.

for whatever entities are listed in the project.

My persistence.xml file looks something like the following.

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">

    <persistence-unit name="Project-ejbPU" transaction-type="JTA">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>jdbc/pool</jta-data-source>

        <class>entity.ZoneTable</class>
        <!--Other classes-->
        <exclude-unlisted-classes>false</exclude-unlisted-classes>

        <properties>
            <property name="eclipselink.weaving" value="static"/>
            <property name="eclipselink.target-server" value="SunAS9"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.logging.level.sql" value="FINEST"/>
            <property name="eclipselink.logging.level" value="FINEST" />
            <property name="eclipselink.logging.level" value="WARNING"/>
            <property name="eclipselink.logging.level.cache" value="FINEST"/>
        </properties>
    </persistence-unit>
</persistence>

The ZoneTable class looks like,

@Entity
@Table(name = "zone_table", catalog = "projectdb", schema = "")
public class ZoneTable implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "zone_id")
    private Long zoneId;

    @Column(name = "zone_name")
    private String zoneName;

    @OneToMany(mappedBy = "zoneTable", fetch = FetchType.LAZY)
    private Set<ZoneCharge> zoneChargeSet;

    //Setters and getters.
}

Here lazy fetching works even with remote EJBs but I think, it is considered eager because of the above warning.

How to enable weaving (or some other way) to avoid this warning?

When I enter this command as mentioned here,

java org.eclipse.persistence.tools.weaving.jpa.StaticWeave

on the command line, I get the following error.

Error: could not find or load main classorg.eclipse.persistence.tools.weaving.jpa.StaticWeave

What are the ways to overcome this warning?


回答1:


Make sure you have the EclipseLink.jar with the org.eclipse.persistence.tools.weaving.jpa.StaticWeave on the classpath when trying to run that class for static weaving.

But if you are running in GlassFish 4 you should not need to use static weaving. Remove the <property name="eclipselink.weaving" value="static"/> property and try deploying again. This property indicates that your classes were already statically enhanced so that dynamic weaving should not occur. Since they weren't enhanced, lazy 1:1 and M:1 will default to eager.



来源:https://stackoverflow.com/questions/18774965/how-to-enable-weaving-in-eclipselink

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!