How can I use IntelliJ IDEA to automatically create foreign key dependencies between tables?

I know that this is not a programming question, rather similar to the question of how to use the-IDE, but at least the context seems to be appropriate.

I already searched for the problem and found this link https://www.jetbrains.com/idea/help/mapping-by-database-schema.html And used it to the best of my abilities, but I still can not achieve what I I'm trying.

Let's say I have table 1 and table2 already generated in the database, and table 1 has a one-to-one column FK "Table2Id".

Since there is talk about setting up table relationships before generation (via joincolumns and attribute types), I would expect that the dialog and the Import Database Database tool could, in addition to creating the obvious columns @Basic and @Id from the DB table, columns can also generate FK relationships in table1 code, something ala

@OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL, optional = true) @JoinColumn(name = "TABLE2ID", nullable = false) private Table2Entity fkEntity; 

But this does not seem to be the case. Actually this confuses more than one.

Firstly, FK columns in tables are not checked by default for generation, therefore, if you just check next to the table name (do not expand the node table to see that the column is not selected), the bean object simply does not get the field associated with this column .

Secondly, the name "attributes" is perplexing. If I check that Table1 should have a table2id column generated in the entity, and I am also trying to add a relation to this column, it complains that I can only use one unique attribute name once. It seems like this might make sense (I'm not sure, however, that choosing to import the relationship instead of the column SHOULD generate the code above), so I tried to cancel the import of the column and select the import of the relationship. Still to no avail.

Finally, if I really choose either the FK column itself or the relation in table1 for import, I cannot check the Identity table2Id column in table2 for import, the complaint is the same, it cannot use the same attribute name more than once ( this doesn't make sense to me, because Table2Entity will need an identifier in the code).

So ... Am I missing something in setting up the import process? I am using IntelliJ 14 Ultimate.

Or should I start learning other tools than IntelliJ?

+6
source share

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


All Articles