我需要创建一个包含两种'模块的数据库。
- 以域名为重点的课程
- 元数据类
醇>
在第一组中,它只是简单(或复杂)RDBMS。第二个块'是元数据类,它从第一个块收集有关类的信息。
我做了什么:
创建的Entity类,它是所有来自第1部分的父级:
@PersistenceAware
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public abstract class Entity implements Serializable {
private static final long serialVersionUID = 1L;
}
创建了普通模式,所有实体都以某种方式继承Entity
类。
创建InternalMapping
类作为整个概念的父级。
@PersistenceCapable
@Inheritance(strategy = InheritanceStrategy.NEW_TABLE)
public abstract class InternalMapping implements Serializable {
private static final long serialVersionUID = 1L;
private Entity entity;
//.. cut off getter and setter
}
创建了应该具有该功能的InternalMapping
子项。
最后我发现它不起作用。可能是因为Entity没有任何字段。但如果是这样,我希望有2个字段:a primary key
和class name
。这样,我会用2个坐标映射每个实体:ID
和class name
。
知道如何解决这个问题吗?最后JDOQL
看起来如何。
诗即可。我知道RDBMS
不是解决这类问题的最佳方案,但与我合作的人希望拥有关系数据库。
答案 0 :(得分:0)
最后,我找到了解决问题的方法。我能够将不同类的实体保存在一个表中。此外,我能够通过过滤特定类的实例来执行JDOQL请求。
该示例位于GitHub存储库中:https://github.com/jgrzebyta/samples-jdo/tree/metalink和metalink
分支内。它是从 datanucleus 示例中略微修改的 Tutorial 项目。
所以
继承层次结构中的最低级别是Core
与内部定义的PK的接口。
班级MyIndex
收集Core
界面的不同实现,即Book
和Product
。此外,我添加了名为type
的新列,仅用于存储Class
名称。我能够检索Core
接口的实现并针对type
提交构建查询过滤器,因为查询类型core instanceof Book
simple不起作用。这是我在我的解决方案中使用的identity
映射策略的功能:DataNucleus JDO Objects。
PS。如果您运行命令mvn -Pschema-gen compile
,则会收到DDL
文件。