How IntelliJ IDEA 10 generate entity (POJO) from DB model ?

How IntelliJ IDEA 10 generate entity (POJO) from DB model ?

Asked on October 27, 2018 in Database.
Add Comment


  • 4 Answer(s)

    First we require disclose to intelliJ that we are utilizing Hibernate (I figure we are whether we require the orm pojo of the table)

    1. Go to “Task structure” (alt+ctrl+shift+s)
    2. In “Task settings” select “Modules”
    3. Press + and include the Hibernate feature in our module.

    Presently we have setup our sleep design feature we can remove our pojos.

    1. At our base right even board we will now observe a tab called “Ingenuity” ( we can’t discover Persistence tab we may indicate it by picking View > Tool Windows > Persistence)
    2. There we can right tap on the sleep symbol named like our module
    3. Go to “Produce Persistence Mapping”- “by database blueprint”
    4. Presently we figure we can discover our direction…
    5. When all is said in done settings select the datasource that we need to utilize and now we can see every one of the tables in our datasource question
    6. Presently we can do numerous things, include associations with the + sign, change the name and sort of the pojo’s properties and so forth note: in the event that we get a blunder and the “alright” is crippled its most likely in light of the fact that the information compose that intelliJ found for our pojo is invalid.
    Answered on October 27, 2018.
    Add Comment

    Default Scripted Extensions Generate POJOs.groovy is not good option when dealing with tables with underscore:

    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]
    }
    

    This code can be used to generate entity (POJO) from data model exploitation IntelliJ plan ten. as we produce “Data source” in IntelliJ and be able to generate the POJO.

    Answered on October 27, 2018.
    Add Comment

    The default Scripted Extensions Generate POJOs.groovy is not very good when dealing with tables with underscore(which is very common).

    So I make some modifications.

    The 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]
    }
    Answered on January 14, 2019.
    Add Comment

    UPDATE:
    In IntelliJ 16 this feature in now implemented. The steps to do it are:
    1. Database view context menu
    2. Scripted Extensions
    3. Generate POJOs

    First you need tell intelliJ that you are using Hibernate (I guess you are if you need the orm pojo of the table)

    1. Go to “Project structure” (alt+ctrl+shift+s)
    2. In “Project settings” select “Modules”
    3. Press + and add the Hibernate facet in your module.

    Now you have setup your hibernate configuration facet you can extract your pojos.

    1. At your bottom right horizontal panel you will now see a tab called “Persistence” (ιf you can’t find Persistence tab you may show it by choosing View > Tool Windows > Persistence)
    2. There you can right click on the hibernate icon named like your module
    3. Go to “Generate Persistence Mapping”-“by database schema”
    4. Now I guess you can find your way…
    5. In general settings select the datasource that you want to use and now you can see all the tables in your datasource object
    6. Now you can do many things, add relationships with the + sign, change the name and type of the pojo’s properties etc. note: if you get an error and the “OK” is disabled its probably because the data type that intelliJ found for your pojo is invalid. Just change it to the one you need and you are ready to go!
    Answered on January 14, 2019.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.