IntelliJ IDEA 10 will generate an object (POJO) from the database model

How can I generate an entity (POJO) from a database model using IntelliJ IDEA 10. I create a "Data Source" in IntelliJ, but I don’t know how I can create a POJO.

+49
database intellij-idea pojo
Mar 10 2018-11-11T00:
source share
2 answers

The steps are simple, but I think it is difficult, since you are used to the eclipse interface (I would feel the same if I had to do this in Eclipse)

First you need to tell intelliJ that you are using Hibernate (I think you if you need an orm pojo table)

  • Go to the "Project Structure" section ( alt + ctrl + shift + s )
  • In the "Project Settings" select "Modules"
  • Click + and add the Hibernate facet to your module.

Now you have configured the sleep configuration facet, you can extract your pojos.

  • In the bottom right horizontal panel, you will see a tab called Resistance (if you cannot find the Save tab, you can show it by choosing View> Tools> Resistance).
  • Here you can right-click on the hibernation icon named as your module.
  • Go to the "Create Persistence Mapping" - "Database Schema" section.
  • Now I think you can find your way ...
  • In the general settings, select the data source that you want to use, and now you can see all the tables in the data source object.
  • Now you can do many things, add relations with a + sign, change the name and type of pojo properties, etc. Note: if you receive an error message and OK is disabled, probably because the data type that intelliJ detected for your pojo is invalid. Just change it to the one you need and you're ready to go!

UPDATE:
IntelliJ 16 now has this feature. The steps for this are:
Database context menu
Script extensions
Creating POJO
https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FIDEA-66037

+89
Mar 10 '11 at 17:59
source share
β€” -

By default, Scripted Extensions Generate POJOs.groovy doesn’t work very well with underlined tables (which is very common).

Therefore, I made some changes.

Main code

 def calcFields(DasObject table) { DasUtil.getColumns(table).reduce([]) { fields, col -> def spec = Case.LOWER.apply(col.dataType.specification) def typeStr = typeMapping.find { p, t -> p.matcher(spec).find() }.value fields += [[ name : javaName(col.name, false), type : typeStr, annos: """ /** * $col.comment */"""]] } } static String javaName(String str, boolean capitalize) { def s = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.UPPER_CAMEL, str); capitalize || s.length() == 1 ? s : Case.LOWER.apply(s[0]) + s[1..-1] } 

Here you can find the whole text https://gist.github.com/aristotll/ad799a7462e8b705b26103944cca24a6

+1
Jul 26 '17 at 4:17
source share



All Articles