A
A
aleksey-lymarev2015-07-08 20:29:41
Java
aleksey-lymarev, 2015-07-08 20:29:41

How to organize automatic recording in JPA?

Hello, I started to study web development in the java language, the task was to write an application without using frameworks, the question arose of how to use Hibernate and JPA to organize Writing to data so that when writing to one table where there is a one-to-many relationship, there was a record in another table n

For example we have a test table and a question table. how to make it so that when adding a test, new questions automatically fall into the table.

Thanks in advance!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Noobkesan, 2015-07-09
@aleksey-lymarev

Something like this:
@ManyToOne(cascade=CascadeType.PERSIST)

B
bromzh, 2015-07-08
@bromzh

If there is data in the field that is marked as a relation, then JPA itself must save related entities, you just need to specify the links correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question