English 中文(简体)
休眠测图最佳获取做法(多对一)
原标题:Best Fetching Practices in Hibernate Mapping (Many-To-One)

我无法用冬眠来绘制许多对一个的地图。我有两个表格,表A和表B。我绘制了这两个表格之间的许多对一个关系。两个表格可以一起使用,也可以分开使用。

以 Java 类计的表格表示如下:

class A{ 
 private B b; 
 private Integer val1; 
 private Integer val2; 
 private Integer val3; 
}

class B{
 private Integer val1;
 private Integer val2;
 private Integer val3;
}

问题是每当我试图从表A中检索/获取记录时,冬眠也会从表B中获取记录,而我并不想这样做,这会造成业绩问题。他们有什么办法应对这种情况吗?

请指引我一个合适的答案

问题回答
@ManyToOne(lazy = true)
private B b;

需要更多细节吗?阅读henate文件

您的要求符合 lazy 初始化 。 要达到此要求, 您可以添加注解, 或者在检索数据时添加注解, 您可以使用冬眠会话 s get 方法 。

在您的情况中,您可以写作如下:

Session session = SessionFactory.getCurrentSession();
A aObject= (A) session.get(A.class, A_ID);

https://community.jboss.org/wiki/AshortprimerOn letchingStategies??_ssc=t"rel="nofollow">https://community.jbos.org/wiki/AshortprimerOn letchingStategies?_ssc=t 链接:

如果您通过获取( ) 或装入( ) 来通过标识取回单个实体, 则 Hibernate3 会装入单个实体实例。 为该实体绘制的所有收藏, 以及所有关联实体, 无论是通过多个关联还是到一个关联, 都没有装入 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签