具有聚合属性的EJB3 / JPA实体(EJB3/JPA entity with an aggregated attribute)
我想知道是否有办法在One2Many关系中获得One Side的一个领域,它是Many方面的聚合。
我们来看下面的例子:
@Entity public class A { @Id private Long id; @OneToMany (mappedBy="parentA") private Collection<B> allBs; // Here I don't know how to Map the latest B by date private B latestB; // Acceptable would be to have : private Date latestBDate; } @Entity public class B { @Id private Long id; private Date date; @ManyToOne (targetEntity=A.class) private A parentA; }
我的问题是如何在A实体对象中进行字段latestB的映射而不进行任何去规范化(不与触发器/侦听器保持同步)?
也许这个问题给出了一些答案,但实际上我不明白它是如何工作的,因为我仍然希望能够获取所有的子对象。
感谢阅读/帮助。
PS:我使用hibernate作为ORM / JPA提供程序,因此如果不存在JPA解决方案,可以提供Hibernate解决方案。
PS2:或者只是告诉我,我不应该这样做(当然有论据);-)I wanted to know if there is a way to get in a One2Many relationship a field of the One side that is an aggregate of the Many side.
Let's take the following example:
@Entity public class A { @Id private Long id; @OneToMany (mappedBy="parentA") private Collection<B> allBs; // Here I don't know how to Map the latest B by date private B latestB; // Acceptable would be to have : private Date latestBDate; } @Entity public class B { @Id private Long id; private Date date; @ManyToOne (targetEntity=A.class) private A parentA; }
My question is how can I make the mapping of the field latestB in the A entity object without doing any de-normalization (not keeping in sync the field with triggers/listeners)?
Perhaps this question gives some answers, but really I don't understand how it can work since I still want to be able to fetch all childs objects.
Thanks for reading/helping.
PS: I use hibernate as ORM/JPA provider, so an Hibernate solution can be provided if no JPA solution exists.
PS2: Or just tell me that I should not do this (with arguments of course) ;-)
原文:https://stackoverflow.com/questions/3709010
最满意答案
哇,我终于解决了这个问题!
看来,即使我没有在日志文件中看到它(参见我的上一条评论),WCExtensionDelegate的
init
方法在唤醒应用程序时也能很好地调用。所以我只需要将WCSession设置块移动到
init
方法中:- (id) init { if (self = [super init]) { // Setup the WatchConnectivity session WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; } return self; }
而且它暂时工作正常......
Wow, I finally resolved the issue!
It seems that, even if I didn't see it in the log files (see my last comment), the
init
method of WCExtensionDelegate is well called when waking up the app.So I just had to move the WCSession setting bloc into the
init
method :- (id) init { if (self = [super init]) { // Setup the WatchConnectivity session WCSession *session = [WCSession defaultSession]; session.delegate = self; [session activateSession]; } return self; }
And for the while it works fine...
相关问答
更多-
我在iPhone设置中关闭了手表应用程序 I turned off the watch app in the iPhone setting
-
Android Wear 2.0架构存在实时并发症问题(Android Wear 2.0 Architecture issues for realtime complications)[2022-07-17]
几件事情要解压缩: 并发症并不意味着经常更新(思考分钟,而不是秒) - 这是为了保存电池。 ProviderUpdateRequester专为(通常不频繁)不定期更新(如通过聊天应用程序发送的消息)而设计。 时间依赖并发症 - 这里没有“更新”,但Wear提供了开发人员从某个时间开始向上/向下计数以及显示日期相关字段(世界时钟,月中的某天)而无需提供者将系统更新全部发送时间。 对于最后一篇,请参考ComplicationText.TimeDifferenceBuilder和ComplicationText. ... -
在WatchKit中解析查询(Parse Query in WatchKit)[2024-01-09]
在WatchKit应用程序中没有UITableView这样的东西。 相反,您必须使用WKInterfaceTable 。 在继续之前,我还建议您阅读WatchKit编程指南中的文档。 它将使您更好地了解作为有抱负的Apple Watch开发人员可用的所有工具集。 WKInterfaceTable 一旦你了解了WKInterfaceTable ,你就会很快发现为什么你的方法存在缺陷有两个原因。 首先,您没有reloadData方法。 WatchKit中的替代方法是setNumberOfRows(_:withR ... -
如何连接和调试定制ClockKit Complications控制器?(How to connect and debug a custom ClockKit Complications controller?)[2022-01-11]
由于您实际上可以选择手表上的复杂功能,因此听起来像项目明智的一切都设置正确。 由于没有达到断点,听起来像复杂功能找不到您的自定义控制器。 由于您使用的是swift,因此您需要指定控制器的模块。 尝试将手表应用程序的plist中的CLKComplicationPrincipalClass值更改为: $(PRODUCT_MODULE_NAME).ComplicationController Since you are actually able to select the complication on th ... -
Apple推荐的在iPhone和手表之间共享信息的方法是通过应用程序组使用共享对象: Apple Watch Programming Guide ,请参阅“使用包含iOS应用程序共享数据”一章。 因此,在设置共享应用程序组之后,您可以使用AppDelegate的applicationDidEnterBackground和applicationWillEnterForeground (或适合您需要的类似方法)在watchkit扩展可以读取的共享对象中写入信息: AppDelegate中 func applic ...
-
不要将hg数字与更改的实际版本号混淆。 (即,在一个仓库中更改88与另一个仓库中的更改88不同,除非它们具有相同的签名代码。日志编号是用于在单个仓库中引用变更集的便捷捷径,但不会在回购中转换)。 如果您有3个不同的存储库,那么几乎不可能避免合并。 通常,hg在自动合并方面做得很合理。 如果你设置一个像样的hgmerge来使用你最喜欢的3路差异设置,即使是偶尔的手动合并也不是那么痛苦。 但是,如果您想尽可能避免合并,则需要选择一个存储库作为“主要”存储库,并从主存储库中进行另一个存储库推送和拉取。 二级回购的 ...
-
据我所知, topic.last_update(@section.topics) 应该: topic.last_update(topic) From what I can tell, topic.last_update(@section.topics) should be: topic.last_update(topic)
-
不可能。 因为Apple Document for watchkit明确提到“ WatchKit扩展不支持后台执行模式,所以它们仅在用户与Apple Watch上的相应应用程序交互时运行。 ” 您可以参考苹果文档Link to Apple Doc 阅读直接与您的iOS应用程序通信 。 Not possible. Because Apple Document for watchkit clearly mentions that "WatchKit extensions do not support backg ...
-
哇,我终于解决了这个问题! 看来,即使我没有在日志文件中看到它(参见我的上一条评论),WCExtensionDelegate的init方法在唤醒应用程序时也能很好地调用。 所以我只需要将WCSession设置块移动到init方法中: - (id) init { if (self = [super init]) { // Setup the WatchConnectivity session WCSession *session = [WCSession defaul ...
-
Device Motion( startDeviceMotionUpdatesToQueue )尚未在WatchOS2中可用( deviceMotionAvailable返回false),可能加速度计可以帮助你startAccelerometerUpdatesToQueue加速度计startAccelerometerUpdatesToQueue Device Motion (startDeviceMotionUpdatesToQueue) is not available in WatchOS2 yet ( ...