English 中文(简体)
有效确定通过“一对一”关系提及的实体的身份
原标题:Efficiently determining the IDs of entities referenced via OneToMany relationship

我要说的是,我有一个自由实体,宣布与另一个实体的关系为

@Entity
public class SomeEntity {
  @OneToMany(fetch = FetchType.LAZY)
  private List<OtherEntity> otherEntities = new LinkedList<OtherEntity>();

  [...]
}

在绘制相应数字格式的<代码>SomeEntity时,我都需要将 OtherEntity确定为首要关键(即,我实际上对<编码>其他意向不感兴趣)。

是否自愿支持这一模式,即只恢复通过<代码>One ToMany关系提及的实体的识别资料?

我不能影响如何检索<代码>SomeEntity(即,我有一份现有的<代码>SomeEntity在本届赫尔辛基会议期间的电信范围内检索的事例),但可以假定, la装尚未发生,因此,仅仅检索儿童物体识别器(而不是完整物体)实际上会产生一种性能效益。

问题回答

Well, if you only need the entities ids and you want to be economical about it, when you get those entities from the database you should state in your query that you only want to get the ids of each entry, using projections, something like :

 SELECT Entity.id as entity FROM Entity WHERE ... 

这将归还与实体的同类物品。

如果没有进入实体,你可以尝试获取主要钥匙(没有<代码>其他意向.getId()。 您可使用<代码>。 常设大学类别:

PersistenceUnitUtil#getIdentifier(yourEntity)

<代码>PersistenceUnitUtil可在上查询。 实体管理/编码。 因此,可以这样说:

EntityManager em = ...  
PersistenceUnitUtil = em.getEntityManagerFactory().getPersistenceUnitUtil();

不幸的是,我不知道这是否会阻止实体装载。 然而,仅仅查阅<代码>其他实体的收集,甚至获得对每个实体的提及,都不会使案件被装上负荷;为了保证其装上载荷,你需要向相关实体援引一种方法。

您也可考虑建立<条码>@NamedQuery,并仅退回。 OtherEntity ID s.

HTH!





相关问题
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 ...