简体   繁体   English

JPA - 运行测试用例时未启用编织

[英]JPA - Weaving not enabled while running test cases

I have an application that uses Eclipselink 2.5, and when running the Junit test cases, I always receive this warning: 我有一个使用Eclipselink 2.5的应用程序,在运行Junit测试用例时,我总是收到此警告:

[EL Warning]: metadata: 2013-08-19 01:14:05.142--ServerSession(14351551)--
Reverting the lazy setting on the OneToOne or ManyToOne attribute [currentTransit]
for the entity class [class ......persistent.entity.BPExecutionEntity] since
weaving was not enabled or did not occur.

So, I wrote a 'weaving' task on my Ant build file like this: 所以,我在我的Ant构建文件上写了一个“编织”任务,如下所示:

<target name="define.task" description="New task definition for EclipseLink static weaving">
    <taskdef name="weave" classname="org.eclipse.persistence.tools.weaving.jpa.StaticWeaveAntTask"/>
</target>
<target name="weaving" description="perform weaving" depends="define.task">
    <weave  source="D:\...\dist\${ant.project.name}.jar"
            target="D:\...\dist\woven-${ant.project.name}.jar"
            persistenceinfo="D:\...\lib\persistence.jar">
        <classpath>
        </classpath>
    </weave>
</target>

OK, everything works, and when I compile the code it generates a woven file half the size of the compiled jar. 好的,一切正常,当我编译代码时,它会生成一个编织文件大小一半的编织文件。 But, when I run the tests of the project then I still receive the same warning blah blah blah... since weaving was not enabled or did not occur. 但是,当我运行项目的测试时,我仍然收到相同的警告blah blah blah... since weaving was not enabled or did not occur.

Anybody knows how to remove this warning from my tests? 有谁知道如何从我的测试中删除此警告?

You need to specify that static weaving is used in your persistence.xml properties. 您需要指定在persistence.xml属性中使用静态编织。 See http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving 请参阅http://wiki.eclipse.org/EclipseLink/UserGuide/JPA/Advanced_JPA_Development/Performance/Weaving/Static_Weaving

"Step 2: Configure persitence.xml" for details “步骤2:配置persitence.xml”以获取详细信息

I finally solved the situation using dynamic weaving. 我终于用动态编织解决了这个问题。 As I'm using Netbeans 7.3.1, I went to the Project Options | Run | VM options 当我使用Netbeans 7.3.1时,我进入了Project Options | Run | VM options Project Options | Run | VM options Project Options | Run | VM options and added this text: -javaagent:C:\\eclipselink\\jlib\\eclipselink.jar , you can change the address to whatever address you have located the eclipselink.jar. Project Options | Run | VM options并添加了以下文本: -javaagent:C:\\eclipselink\\jlib\\eclipselink.jar ,您可以将地址更改为您在eclipselink.jar中找到的任何地址。

Then I added this line to the persistence.xml : 然后我将此行添加到persistence.xml

<property name="eclipselink.weaving" value="true"/>

That's all. 就这样。 This configuration enables dynamic weaving to execute test cases and removes the [EL Warning] Reverting the lazy setting on the OneToOne or ManyToOne attribute...etc. 此配置允许动态编织执行测试用例并删除[EL Warning] Reverting the lazy setting on the OneToOne or ManyToOne attribute...etc.

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM