D
D
DDwrt1002019-08-27 10:53:54
Java
DDwrt100, 2019-08-27 10:53:54

How to correctly insert a record into a linked table in Hibernate?

Good afternoon, could you please tell me what to do in this situation?
There is a database.
It has a main table with results, and a couple of tables with clarifying entries, it reflects what the measurement was done in.
In the code it looks like this, I removed everything unnecessary. Of course, all this is covered with annotations.
first table

private int id;
private float result;
private index index;

Second table
private int id;
private String name;

The question is, when I write the results to the database, I cannot put the value 1 in the index field, this cannot be done from the Java side, since type incompatibility is obtained.
It turns out that I need to additionally create a table class for each insertion, assign an int id to this class? Or should I first request a table of measurement indexes from the database and substitute the required option from the collection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Senior Devosaur, 2019-08-27
@DDwrt100

I understand you have one entity and several tables for it? Are you using @SecondaryTable to link tables?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question