OneToMany in Hibernate?


Warning: count(): Parameter must be an array or an object that implements Countable in /home/styllloz/public_html/qa-theme/donut-theme/qa-donut-layer.php on line 274
0 like 0 dislike
40 views
Comrades please help, th something not catch up.
In General there are two classes of "Reference" and "Field guide".
Both classes are written in HibernateSessionFactoryUtil:
configuration.addAnnotatedClass(Dictionary.class); configuration.addAnnotatedClass(DictionaryContent.class);

successfully created in the database, but actually they are:

@Entity @Table(name = "sys_dictionaries") public class Dictionary { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column UUID guid = UUID.randomUUID(); @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true) private Set dictionaryContents = new HashSet<>(); ............................. }


@Entity @Table(name = "sys_dictionaries_content") public class DictionaryContent { @Id @GeneratedValue(strategy = GenerationType.IDENTITY) private int id; @Column UUID guid = UUID.randomUUID(); @Column UUID dictionaryId; ........................ }


I'd love a child record (DictionaryContent ) to associate with the Dictionary by means of its UUID identifier.

Now when I save the object Dictionary, passing in the collection of DictionaryContent, all successfully recorded in your table, but the table DictionaryContent, you do not receive any ID-pointer to the parent Dictionary.

Screen tables DictionaryContent:
5c03f5b8b3b7e953674217.png
by | 40 views

1 Answer

0 like 0 dislike
Hello!
I only studied Java development (hibernate, spring etc.)
I'd love a child record (DictionaryContent ) to associate with the Dictionary by means of its UUID identifier.

You need to use OneToMany & ManyToOne. From the Dictionary you get a list of records DictionaryContent (List or Set), and from the DictionaryContent get a Dictionary object.

@Entity public class Dictionary { @OneToMany(mappedBy = "dictionary") private List contentList; } @Entity public class DictionaryContent { @ManyToOne @JoinColumn(name = "id") private Dictionary dictionary; }


however, in table DictionaryContent, you do not receive any ID-pointer to the parent Dictionary.

this is because from the DictionaryContent most likely you are not tied, as in the example above.

A good example https://devcolibri.com/%D0%BA%D0%B0%D0%BA-%D1%81%D...
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
asked May 22, 2019 by sananbozkurt
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
35,534 users