gpt4 book ai didi

java - 如何在序列化之前实例化 LAZY 关系?

转载 作者:搜寻专家 更新时间:2023-10-30 20:04:24 27 4
gpt4 key购买 nike

我刚刚创建并加入了 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'

所有这些错误是什么意思?我不明白,因为所有的列和行都映射得很好……它说找不到某些列……我一遍又一遍地检查了我所有的表,我真的不明白什么可能错了...一切似乎都很好...非常感谢您的帮助!谢谢

此外,我还为应用程序使用了以下内容:网 bean 玻璃鱼mysql大多数jsp页面

最佳答案

实例化惰性引用的问题是众所周知的,所以我将提供一个链接而不是解释我自己:http://en.wikibooks.org/wiki/Java_Persistence/Relationships#Serialization.2C_and_Detaching

Wiki 页面也有 3 个解决方案来解决这个问题。但我会为您提供另一种可能适合您情况的解决方案:JSP 用法。

检查 https://dzone.com/articles/open-session-view-design (或者只是在谷歌上搜索“在 View 中打开 session ”。许多页面都提到了 Hibernate,但它也适用于 Eclipselink)。解决方案是在 servlet 过滤器中启动和结束事务。事务将涵盖整个请求处理。在您的情况下,JSP 页面生成将在事务内进行,惰性引用将正常工作。好处是您不必修改代码。

我不知道你的第二个映射问题

关于java - 如何在序列化之前实例化 LAZY 关系?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29586238/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com