Generate POJOs @OneToMany with groovy intellij idea
I migrated my project from Netbeans to IntelliJ Idea, so far almost everything has worked great, however, I have had problems mapping my entities as Netbeans did. I have modified the script in groovy and I have succeeded almost everything, except when trying to get the JPA @OneToMany relationship, this association is very important according to the model of my database.
After doing several tests (and failing) with the different methods of the class (com.intellij.database.util.DasUtil) I decided to try to execute a query that returns all the tables in relation @OneToMany of the table in generation.
However, I have not succeeded in reusing the data source connection to the database from this script, nor when creating a new connection to run this query and solve my problem. So, is it possible that with the classes provided by IntelliJ to mapper this type of association ?, or how can I create a new connection to the DB from this script, taking into account that I already use the @Grab annotation to import the driver JDBC ?
I hate having to open Netbeans again just to mapper my entities, any ideas to solve this? i use latest version to intellij idea (2019.2.2).
I duplicate this post in stackoverflow for find one fast solution:
https://stackoverflow.com/questions/58345076/generate-pojos-onetomany-with-groovy-intellij-idea
请先登录再写评论。
Does https://stackoverflow.com/questions/5259276/intellij-idea-10-generate-entity-pojo-from-db-model help?
No, this does not work for me. The problem is not to mapper the entities, it is to obtain the @OneToMany relationship of entities, also taking into account that their association fetch is of the lazy type.
Hi! if the main problem is to deal with @OneToMany-like relations, consider using
It is used in another provided code generation script called "Generate Kotlin entities" - it's located next to "Generate POJOs" script you are trying to modify - you can refer it as an example.
In fact you can try kotlin script itself - it uses file templates mechanism which allows you to modify result content easy enough
Hi Nikita Katkov, I already try the file "Generate Kotlin Entities.kts" and the JpaScriptsHelper.calculate utility get the type of relationship (OneToMany - ManyToOne) as I need. However modifying the code is still somewhat confusing because there are not many documentation. Where can I find the library (code) of com.intellij.jpa.scripts.JpaScriptsHelper to see their methods and how to apply them to solve my problem? Search in all intellij directories without getting any results. Is it possible to use it from my .groovy file? Thank you so much for you answer.