6

I know it's not specifically a programming question, more like a how-to-use-an-IDE question, but at least the context seems appropriate.

I already sought the problem out 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 cannot achieve what I'm trying.

Let's say I have a Table1 and a Table2 already generated within a DB, with Table1 having a One-To-One FK "Table2Id" column.

Since there is talk of configuring table relationships before generating (via joincolumns and attribute types) I would expect that the "Import Database Schema" dialog and tool could, aside from generating the obvious @Basic and @Id columns from the DB table columns, also be able to generate FK relations in the Table1Entity code, something ala

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

But, it does not seem to work like that. In fact it is confusing in more ways than one.

Firstly, the FK columns in tables are defaultly unchecked for generation, so if one simply checks next to the table name (not expand the table node to see that the column is not selected), the entity bean simply does not get a field mapped to that column.

Secondly, the naming of the "attributes" is bewildering. If I check that Table1 should have the Table2id column generated in the entity and I try to also add a relationship on that column, it complains that I can only once use one unique attribute name. Which seems that it might make sense (I am not, however, sure that selecting to import the relationship instead of the column SHOULD generate the code above) so I tried to deselect the column import and select to import the relationship. Still to no avail.

Lastly, if I do select either the FK column itself, or the relationship in Table1 for import, I cannot check the Table2Id identity column in Table2 for import, the complaint is the same, it cannot use the same attribute name more than once (this doesn't really make sense to me, because the Table2Entity would need the id in the code).

So... Am I missing something in configuring the Import process? I am using IntelliJ 14 Ultimate.

Or should I start looking into other tools, rather than IntelliJ?

Andy David
  • 83
  • 5
  • 1
    You're not alone, I have a problem getting it to reverse engineer also. There's a thread going on over at superuser. https://superuser.com/questions/1000330/hibernate-entities-generated-using-intellij-have-no-foreign-keys-generated I'm adding this here since this post came up first in a Google search, and you should know (a year later). – kevingreen Feb 03 '16 at 20:28

0 Answers0