gpt4 book ai didi

android - ormlite是否支持继承?

转载 作者:可可西里 更新时间:2023-11-01 18:47:19 26 4
gpt4 key购买 nike

ormlite 是否支持这三种继承策略?

  • 每个类层次结构的表
  • 每个子类的表
  • 每个具体类的表

我找到了 this discussion on the ORMLite user group ,但我不确定它是否回答了我的问题。

特别是我想使用“每个类层次结构的表”。如果 ormlite 框架不支持它们,我将制作一个类并忘记继承,但我更愿意使用继承。

最佳答案

ORMLite不自动支持这些,不。我不确定您是否真的阅读了链接到的线程,因为它非常具体:

What I need is: If I have class A as a superclass, and I have direct subclasses B and C, and I run a query for all records/objects of class A, I do want to have all objects of class A, B and C returned.

是的,ORMLite 不这样做,目前我没有计划支持它。除非我对如何实现这一点有误,否则它的复杂性超出了我所说的“精简版”。 Hibernate 支持此类结构的方式是使用外键、多个表和魔术连接。

这个问题给出了一些关于如何使用 ORMLite 实现继承的想法:

1) You could have class A and an associated table -- so it can't be abstract. Then you could have have B and C which subclass A and have all of As fields each in a separate table. You could then create a special DAO for A which would also query for B and C and add them into your results for A.

2) Another way to do it is you could make classes B and C not be subclasses but instead have a foreign object to A. You can then query all of the As and some of them would be B's A part and some C's A part and some just A. You then could also query Bs and Cs and use the A DAO to refresh and get the A's fields you would not be able to cast. A could also have some sort of enum which said whether it was a A, B, or C. You could also do some magic where you could say getSubClassObject(), if would look at the enum and query the B or C dao for the associated object with the right foreign key for the A object.

关于android - ormlite是否支持继承?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10188414/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com