- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有下表...
Object1
-------
id
...
Object2
-------
id
...
AttributeValue
--------------
id
attribute_id
object_id
value
Attribute
---------
id
name
type
...和实体类
@Entity
@Table(name = "Attribute")
public class Attribute {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "name")
private String name;
@Column(name = "type")
private String type;
}
@Entity
@Table(name = "AttributeValue")
public class AttributeValue {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "attribute_id")
private Long attributeId;
@Column(name = "object_id")
private Long objectId;
@Column(name = "value")
private String value;
}
@Entity
@Table(name = "Object1")
public class Object1 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
// ...
// how to annotate to get all matching attribute values?
private Set<AttributeValue> values;
}
我希望 Hibernate 使用具有相应 object_id
和属性类型 object1
的所有 AttributeValue
填充 values
实例变量。
如果只是关于object_id
的标准,我会写例如
@JoinColumn(insertable = false, updatable = false, name = "object_id")
private Set<AttributeValue> values;
但在这种情况下,它还会填充类型为 object2
等的值。
所以我的问题是:这种语义可以在 Hibernate 中表达吗?如果可以,如何表达?
编辑:我想强调的是,目标是拥有多个对象(此处为Object1
、Object2
、...ObjectN
),这些对象没有共同的层次结构,但都共享具有属性的功能。所有对象的属性将驻留在一个表中,通过某种鉴别器(此处示例为类型
)进行区分。
最佳答案
我认为该对象一定是:
@Entity
@Table(name = "AttributeValue")
public class AttributeValue {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Column(name = "attribute_id")
private Long attributeId;
@ManyToOne
@JoinColumn(name="object_id", nullable=false)
private Object1 object1;
@Column(name = "value")
private String value;
}
@Entity
@Table(name = "Object1")
public class Object1 {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@OneToMany(mappedBy="object1")
private Set<AttributeValue> values;
}
Hibernate 将仅在 AttributeValue 表上生成 object_id 列。
关于java - Hibernate:如何使用第三个表将属性与条件连接起来,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55240681/
我正在尝试执行 vagrant up 但一直遇到此错误: ==> default: IOError: [Errno 13] Permission denied: '/usr/local/lib/pyt
我在容器 div 中有一系列动态创建的不同高度的 div。 Varying text... Varying text... Varying text... Varying text.
通过 cygwin 运行 vagrant up 时遇到以下错误。 stderr: /bin/bash: /home/vagrant/.ansible/tmp/ansible-tmp-14872260
今天要向小伙伴们介绍的是一个能够快速地把数据制作成可视化、交互页面的 Python 框架:Streamlit,分分钟让你的数据动起来! 犹记得我在做机器学习和数据分析方面的毕设时,
我是 vagrant 的新手,正在尝试将第二个磁盘添加到我正在用 vagrant 制作的虚拟机中。 我想出了如何在第一次启动虚拟机时连接磁盘,但是当我关闭机器时 然后再次备份(使用 'vagrant
我是一名优秀的程序员,十分优秀!