The introduction of sleep mode and a key pair

I would like to create several classes that are in the narrow shell of a map of a pair of key values. What is the best appoarch to retrieve or store these classes in a database using hiberate? What are the correct sleep mode annotations to get the job done?

In the database, I expect this to be data generation

class1, field1, value1 class2, field2, value2 class1, field2, somevalue1 ... 

On the java side, I might have

 @Table("some_db_table") class KeyValuePairs { private HashMap<String, String> map; ... } class Class1 extends KeyValuePairs { private Stirng id = "class1"; ... } class Class2 extends KeyValuePairs { private Stirng id = "class2"; ... } 
+4
source share
1 answer

I think you have a ready-made implementation here http://www.java2s.com/Code/Java/Hibernate/HibernateCollectionMappingMap.htm

Check if this is useful (you can create your subclasses exactly as you mentioned)? This creates two tables that are good practice, since you want to keep your primary key, which is not used for business logic. IF you do not want this, then you can always customize it.

+1
source

Source: https://habr.com/ru/post/1301302/


All Articles