简体   繁体   English

如何在Glassfish和Toplink Essentials中使用惰性属性加载

[英]How to use lazy property loading with glassfish + toplink essentials

I have a query: 我有一个查询:

select p from Product p

Which gives me the results I expect, but one of the columns (let's call it massiveDescription ) is big, and since I'm querying the full list of products I want to exclude it. 这给了我预期的结果,但是其中一列(我们称其为massiveDescription )很大,并且由于我要查询的是产品的完整列表,因此我想排除它。

I added @Basic(fetch=FetchType.LAZY) to getMassiveDescription() but this made no difference (the generated sql still includes all columns). 我在getMassiveDescription()添加了@Basic(fetch=FetchType.LAZY)getMassiveDescription()没有区别(生成的sql仍然包括所有列)。

I'm using glassfish pretty much out of the box, and it uses toplink essentials. 我几乎是开箱即用的使用glassfish,它使用了toplink要素。 I thought there might be something I had to do to configure the agent, so I tried adding -javaagent:/path/to/toplink-essentials-agent.jar in the JVM options through the glassfish web interface. 我以为可能需要做一些配置代理程序的工作,所以我尝试通过glassfish Web界面在JVM选项中添加-javaagent:/path/to/toplink-essentials-agent.jar Then I get an exception: 然后我得到一个例外:

java.lang.NoClassDefFoundError: javax/transaction/Synchronization
        at ...

So I figure I need to add jta.jar to the classpath suffix box in the glassfish web ui. 所以我想我需要在glassfish Web ui的classpath后缀框中添加jta.jar That gives me a different exception: 那给了我一个不同的例外:

java.lang.NoClassDefFoundError: oracle/toplink/essentials/transaction/JTASynchronizationListener
        at oracle.toplink.essentials.transaction.JTATransactionController.<init>...

So now I'm chasing jars. 所以现在我在追罐子。 I add toplink-essentials.jar to the classpath in the same way, but I still get the same exception. 我以相同的方式将toplink-essentials.jar添加到类路径中,但是仍然遇到相同的异常。

I have a few questions: 我有几个问题:

  • Is glassfish supposed to support bytecode enhancement for lazy property loading out of the box? Glassfish是否应该支持字节码增强功能以​​方便地进行惰性属性加载?
  • If not, am I missing the correct way to configure it? 如果没有,我是否缺少正确的配置方式?
  • I read that the "recommended" way to achieve this is using a project to select only part of the entity in the query. 我读到实现此​​目的的“推荐”方法是使用项目仅选择查询中实体的一部分。 I like that better, but can't find any documentation on how to do it. 我比较喜欢它,但是找不到有关该方法的任何文档。 Swapping select p for select p.id, p.name, ... gives me strange errors - but I was only guessing at the syntax anyway. select p select p.id, p.name, ...select p.id, p.name, ...会给我带来奇怪的错误-但是我只是在猜测语法。

Turns out toplink essentials doesn't support this. 事实证明toplink基本要素不支持此功能。 Eclipselink does, so looks like I'm moving ORMs. Eclipselink可以,所以看起来我正在移动ORM。

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

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