空瞬态属性
我有一个用 @PrePersist 注释进行注释的方法,但我发现当执行此方法时,我的所有瞬态属性(带有 @Transient 注释的属性)均为 null。
当我调试应用程序时,我可以看到在调用 persist() 方法之前此瞬态属性不为 null,并且当它进入我的 PrePersist 方法时,所有瞬态属性都更改为 null。
PostPersist 方法也会发生这种情况,我需要此方法中的瞬态信息。
这种行为正常吗? 如果不将此信息保存在数据库中,我可以避免这种情况吗?
如果它有帮助我使用 Hibernate 3.5 和 JPA 2。
谢谢
I have a method annotated with @PrePersist annotation but I've seen that when this method is executed all my transient attributes (the attributes with the @Transient annotation) are null.
When I debug the applicaion I can see that this transient attributes are not null just before calling the persist() method and when it enters my PrePersist method all transient attributes changes to null.
It also happens with PostPersist methods and I need the transient information in this methods.
Is this behaviour normal?
Can I avoid it without saving this information in my database?
If it helps I use Hibernate 3.5 and JPA 2.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这类似于这个问题,它有更详细的答案。基本上瞬态信息会在幕后丢失。你对此无能为力。
This is similar to this question which has a more detailed answer. Basically transient information is lost under the hood. There isn't too much you can do about it.