简体   繁体   English

为什么在ManyToOne关联中看不到休眠代理对象?

[英]Why am I not seeing hibernate proxy objects in my ManyToOne associations?

According the the hibernate docs , my @ManyToOne relationships should have proxy objects by default. 根据休眠文档 ,默认情况下,我的@ManyToOne关系应该具有代理对象。 However, when I look at an expanded object in the Eclipse debugger ("Variables" view), it looks like the field variables are instances of the base type as defined in the entity class. 但是,当我在Eclipse调试器(“变量”视图)中查看扩展对象时,看起来字段变量是实体类中定义的基本类型的实例。 Moreover, when I call session.get(type, id) with hibernate.show_sql=true I can see left outer join s for all @ManyToOne relationships defined on the object. 此外,当我使用hibernate.show_sql=true调用session.get(type, id) ,我可以看到对象上定义的所有@ManyToOne关系的left outer join @ManyToOne

Is there something specific that needs done in order for Hibernate to create proxy classes/objects for these relationships? 为了让Hibernate为这些关系创建代理类/对象,是否需要做一些特定的事情? Perhaps bytecode enhancement? 也许字节码增强?

Quote from hibernate docs: 引用休眠文档:

Lazy fetching for collections is implemented using Hibernate's own implementation of persistent collections. 使用Hibernate自己的持久性集合实现来实现集合的懒惰获取。 However, a different mechanism is needed for lazy behavior in single-ended associations. 但是,单端关联中的惰性行为需要不同的机制。 The target entity of the association must be proxied. 协会的目标实体必须被代理。 Hibernate implements lazy initializing proxies for persistent objects using runtime bytecode enhancement which is accessed via the bytecode provider. Hibernate使用运行时字节码增强功能(通过字节码提供程序访问)为持久对象实现延迟初始化代理。

At startup, Hibernate generates proxies by default for all persistent classes and uses them to enable lazy fetching of many-to-one and one-to-one associations. 在启动时,默认情况下,Hibernate会为所有持久类生成代理,并使用它们来实现多对一和一对一关联的延迟获取。

All @ManyToOne and @OneToOne associations are EAGER by default , that's why they are JOINED when you fetch the root entity. 默认情况下 ,所有@ManyToOne@OneToOne关联都为EAGER ,这就是为什么当您获取根实体时将它们关联在一起的原因。

A proxy is used only if the association is not initialized. 仅当关联未初始化时才使用代理。 To make your associations LAZY, you just need to add the LAZY fetch attribute: 要使您的关联为LAZY,您只需添加LAZY fetch属性:

@ManyToOne(fetch = FetchType.LAZY)

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

相关问题 Hibernate 使用 ManyToOne 删除所有引用 object 单向的对象关联 - Hibernate delete all objects associations that reference the object unidirectional using ManyToOne 为什么在Java应用程序中看到“奇怪的”滚动条? - Why in my Java application am I seeing “strange” scrollbars? 为什么我看不到我的Java / SalesForce / Google App? - Why am I not seeing my Java / SalesForce / Google App? 休眠ManyToOne保存对象 - Hibernate ManyToOne saving objects 为什么在Java 1.7.0中看到ConcurrentModificationException? - Why am I seeing ConcurrentModificationException in Java 1.7.0? 为什么在我的标准输出println之后我看不到我的stderr println? - Why am I not seeing my stderr println after my stdout println? 为什么解析json响应时会看到最后一个项目? - Why am i seeing the last item when parsing my json response? 为什么Hibernate ManyToOne无法正确持久保存? - Why Hibernate ManyToOne is not persisted correctly? 如何使用具有ManyToMany关联的嵌套对象在Hibernate中正确分页? - How do I correctly paginate in Hibernate with nested objects with ManyToMany associations? 我不明白为什么我在数组列表中看到了两次索引,尽管在第一次出现后删除了它 - I do not understand why I am seeing an index from my array list twice despite having removed it after the first occurrence
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM