java - 内部类作为 hibernate 组件

标签 java hibernate inner-classes

基本上,这可能吗

文档说

A component is a contained object that is persisted as a value type and not an entity reference.

Like value types, components do not support shared references. In other words, two persons could have the same name, but the two person objects would contain two independent name objects that were only "the same" by value.

The main distinguishing characteristic of a value type is the fact that they do not define their own lifecycle. We say that they are "owned" by something else (specifically an entity, as we will see later) which defines their lifecycle.

非静态内部类可以完美地适应这一点,但我从未见过实践中的例子。使用内部类作为组件有什么限制吗?

最佳答案

JPA 规范说:

Embeddable classes must adhere to the requirements specified in Section 2.1 for entities with the excep- tion that embeddable classes are not annotated as Entity.

第 2.1 节说:

The entity class must be a top-level class.

关于java - 内部类作为 hibernate 组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27745374/

相关文章:

java - Spring Boot JPA 按条件选择获取 NullPointerException

java - 如何通过自定义方法从Java中的属性文件中获取值

oracle - Hibernate:使用增量和 Oracle 模式的 ID 生成器

java - 成员类访问修饰符

java - 方法本地内部类与内部类

java - 如何防止关闭JFrame时在JFrame前面弹出JDialog?

java - 在 Java 中共享类属性

java - Hibernate session 关闭异常,当10个或更多用户访问页面时

java - 如何查询实体并将计数聚合到值对象上

c++ - 在C++中使用模板类的嵌套类作为模板模板参数