JPA annotations for an association table generation
I have a simple demonstration application with a product table, a component table, and an association table between them called product_component. Using the persistence window, I can easily generate entities from the database schema, however what I have found through a great deal of experimentation is that the oneToMany annotations and associated fields are not generated in the product and component tables unless I run the mapping twice. The first time I run the mapping, I leave "Show default relationships" unchecked. I run it again without deleting the entities but with "Show default relationships" checked. The second time, it generates fields and correct annotations in all generated entities.
I am using the Idea Ultimate version 2018 beta 3. Is this a bug of some sort, or am I missing something about the way the generation is handled in Spring that would require two passes?
Please sign in to leave a comment.
Hello Keith,
Whay don't you check "Show default relationships" on the first run? Does it generates wrong code with this option enabled?
Yaroslav,
I did check it the first time and found that what it generated was inconsistent. The join table class always is generated correctly, but the other classes (product and component) sometimes were generated correctly and sometimes not. When I say incorrectly, I mean that they did not include the code related to the join. I did a great deal of experimenting and it seemed that whether it worked or not was almost random. The two step process above - as illogical as it is -- seems to consistently work.
As a followup, I just created a new project from scratch and had exactly the same result. I generated the entities with the checkbox checked for relationships and found that only then join entity was correctly filled in. Then I deleted the classes, generated the entities first _without_ the checkbox and then with and all worked as it should. Very odd.
Keith,
What Database do you use?
I am using PostgreSQL version 11
Keith,
I reported issue on YouTrack: https://youtrack.jetbrains.com/issue/IDEA-202303
Please follow it for updates.