0

I need to have a table of Registered_Systems with System_id, name, description etc. Now each System can have n number of attributes which I have planned to store in a child table Registered_System_Attributes(System_id,Attribute_name, Attribute_Value ) with a foreign key to Registered_Systems.System_id

As an Attribute must have a System associated, I was planning to make the class RegisteredSystemAttribute as Embeddable and define

@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;
 ...
}

If modeled this way, how to return System names based the attribute name & the value supplied?

Any help on this is more than welcome.

I am using

  • 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) hibernate-jpa-2.0-api-1.0.1.Final-redhat-2.jar offered by JBOSS EAP 6.3
lab bhattacharjee
  • 1,617
  • 2
  • 17
  • 33
  • Have you read posts like this one ... querying elements of an embedded collection https://stackoverflow.com/questions/11768528/querying-a-collection-of-embeddable-elements-using-eclipselink – Neil Stockton Aug 21 '16 at 10:45
  • @NeilStockton, Thanks. I read http://stackoverflow.com/questions/3708914/jpa-2-using-elementcollection-in-criteriaquery – lab bhattacharjee Aug 21 '16 at 11:27

1 Answers1

1

I think what you are looking for are JPA 2.1 map collections (JSR 388, section 2.7). So in your case:

@ElementCollection
@CollectionTable(name="Registered_System_Attributes")
@MapKeyColumn(name="Attribute_name")
@Column(name="Attribute_Value")
private Map<String, String> registeredSystemAttributes;
8hZWKA
  • 433
  • 3
  • 12