如何在序列化之前实例化 LAZY 关系?
How to instantiate the LAZY relationship prior to serialization?
我刚刚创建并加入了 3 个新表。在创建它们之前一切正常,所以我相信根本原因来自于它们的创建。现在在浏览器中运行时我收到此错误:
org.apache.jasper.JasperException: Exception [EclipseLink-7242]
(Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd):
org.eclipse.persistence.exceptions.ValidationException
Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often
occurs when an entity with an uninstantiated LAZY relationship is
serialized and that lazy relationship is traversed after
serialization. To avoid this issue, instantiate the LAZY relationship
prior to serialization.
如何在序列化之前实例化 LAZY 关系?我一直在网上寻找,但我仍然没有找到真正可行的解决方案...
我还收到其他错误消息:
Exception [EclipseLink-4002] (Eclipse Persistence Services -
2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Unknown column 't1.rating' in 'field list' Error Code: 1054 Call:
SELECT t1.id, t1.description, t1.last_update, t1.name, t1.price,
t1.rating FROM category_has_product t0, product t1 WHERE
((t0.category_id = ?) AND (t1.id = t0.product_id)) bind => [1
parameter bound] Query: ReadAllQuery(name="productCollection"
referenceClass=Product sql="SELECT t1.id, t1.description,
t1.last_update, t1.name, t1.price, t1.rating FROM category_has_product
t0, product t1 WHERE ((t0.category_id = ?) AND (t1.id =
t0.product_id))")
root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown
column 't1.rating' in 'field list'
所有这些错误是什么意思?我不明白,因为所有的列和行都映射得很好……它说找不到某些列……我一遍又一遍地检查了我所有的表,我真的不明白什么可能错了...一切似乎都很好...非常感谢您的帮助!谢谢
此外,我还为应用程序使用了以下内容:
网豆
玻璃鱼
Mysql
jsp
中的大多数页面
实例化惰性引用的问题是众所周知的,所以我将提供一个 link 而不是解释我自己:http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Serialization.2C_and_Detaching
维基页面也有3个解决方案来解决问题。但我会为您提供另一种解决方案,可能适合您的情况:JSP 用法。
检查 https://dzone.com/articles/open-session-view-design(或 google 'open session in view'。许多页面提到 Hibernate,但它也适用于 Eclipselink)。解决方案是在 servlet 过滤器中启动和结束事务。事务将涵盖整个请求处理。在您的情况下,JSP 页面生成将在事务内进行,惰性引用将正常工作。好处是您不必修改代码。
我不知道你的第二个映射问题
我刚刚创建并加入了 3 个新表。在创建它们之前一切正常,所以我相信根本原因来自于它们的创建。现在在浏览器中运行时我收到此错误:
org.apache.jasper.JasperException: Exception [EclipseLink-7242] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException Exception Description: An attempt was made to traverse a relationship using indirection that had a null Session. This often occurs when an entity with an uninstantiated LAZY relationship is serialized and that lazy relationship is traversed after serialization. To avoid this issue, instantiate the LAZY relationship prior to serialization.
如何在序列化之前实例化 LAZY 关系?我一直在网上寻找,但我仍然没有找到真正可行的解决方案...
我还收到其他错误消息:
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 't1.rating' in 'field list' Error Code: 1054 Call: SELECT t1.id, t1.description, t1.last_update, t1.name, t1.price, t1.rating FROM category_has_product t0, product t1 WHERE ((t0.category_id = ?) AND (t1.id = t0.product_id)) bind => [1 parameter bound] Query: ReadAllQuery(name="productCollection" referenceClass=Product sql="SELECT t1.id, t1.description, t1.last_update, t1.name, t1.price, t1.rating FROM category_has_product t0, product t1 WHERE ((t0.category_id = ?) AND (t1.id = t0.product_id))")
root cause
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column 't1.rating' in 'field list'
所有这些错误是什么意思?我不明白,因为所有的列和行都映射得很好……它说找不到某些列……我一遍又一遍地检查了我所有的表,我真的不明白什么可能错了...一切似乎都很好...非常感谢您的帮助!谢谢
此外,我还为应用程序使用了以下内容: 网豆 玻璃鱼 Mysql jsp
中的大多数页面实例化惰性引用的问题是众所周知的,所以我将提供一个 link 而不是解释我自己:http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Serialization.2C_and_Detaching
维基页面也有3个解决方案来解决问题。但我会为您提供另一种解决方案,可能适合您的情况:JSP 用法。
检查 https://dzone.com/articles/open-session-view-design(或 google 'open session in view'。许多页面提到 Hibernate,但它也适用于 Eclipselink)。解决方案是在 servlet 过滤器中启动和结束事务。事务将涵盖整个请求处理。在您的情况下,JSP 页面生成将在事务内进行,惰性引用将正常工作。好处是您不必修改代码。
我不知道你的第二个映射问题