簡體   English   中英

JPA \\ Hibernate:Singleton中的實體的持久列表

[英]JPA\Hibernate: Persisted list of entities in Singleton

我有一個單身人士,負責管理數據庫中某些實體的列表。

public class SchedulledQueue {
    List<MyEntity> entities;
}

我需要將此列表存儲在數據庫中。 所以我想要一個只包含實體的表,我的單例可以從中獲取所有數據。

TABLE schedulled_queue 
(
  entity_id character varying(32),

  CONSTRAINT schedulled_queue FOREIGN KEY (entity_id)
      REFERENCES tbl_my_entity (entity_id) MATCH SIMPLE
)

有什么辦法可以在Hibernate中映射我的單例SchedulledQueue來實現這一目標? 還是我不應該為這樣的事情而煩惱?

如果您有多個SchedulledQueue對象,則在SchedulledQueue和MyEntity之間具有一對多關系是有意義的。

由於您的SchedulledQueue在單例中。 我看不到創建它的實體的任何優勢。

因此,除了創建另一個實體並通過DAO使用它之外,我沒有找到其他方法。

public class SchedulledQueue {
    List<SchedulledQueueEntity> entities;
}

SchedulledQueueEntity {
    MyEntity ent;
}

它還提供了對隊列中的實體使用一些其他字段的功能,這是我們稍后需要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM