【发布时间】:2016-08-21 09:12:14
【问题描述】:
我需要有一个带有 System_id、名称、描述等的 Registered_Systems 表。现在每个系统可以有 n 个属性,我计划将这些属性存储在子表 Registered_System_Attributes(System_id,Attribute_name, Attribute_Value) 中,并带有外键到 Registered_Systems.System_id
由于属性必须与系统关联,我打算将类 RegisteredSystemAttribute 设为Embeddable 并定义
@Entity
@Table(name = "Registered_Systems")
public class RegisteredSystem {
...
@ElementCollection
@CollectionTable(name = "Registered_System_Attributes", joinColumns = { @JoinColumn(name = "System_id", referencedColumnName = "System_id") })
private Set<RegisteredSystemAttribute> registeredSystemAttributes;
...
}
如果以这种方式建模,如何根据属性名称和提供的值返回系统名称?
非常欢迎对此提供任何帮助。
我正在使用
- spring-data-commons-1.6.3.RELEASE.jar
- spring-data-jpa-1.4.3.RELEASE.jar
- (i)hibernate-entitymanager-4.2.14.SP1-redhat-1.jar,(ii) JBOSS EAP 6.3 提供的hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar
【问题讨论】:
-
你读过这样的帖子吗...查询嵌入式集合的元素stackoverflow.com/questions/11768528/…
-
@NeilStockton,谢谢。我读了stackoverflow.com/questions/3708914/…
标签: jpa spring-data-jpa jpql