IntelliJ IDEA 10从DB模型生成实体(POJO) [英] IntelliJ IDEA 10 generate entity (POJO) from DB model

查看:3833
本文介绍了IntelliJ IDEA 10从DB模型生成实体(POJO)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用IntelliJ IDEA 10从数据库模型生成实体(POJO)。我在IntelliJ中创建了数据源,但我不知道如何生成POJO。

首先你需要告诉intelliJ你正在使用Hibernate(我想你是如果你需要表的orm pojo)


  1. 转到项目结构
    alt + ctrl + shift +


  2. 现在你已经设置了你的hibernate配置facet,你可以提取你的pojos。


    1. 在右下方的水平面板中,您将看到一个名为
      的选项卡。Persistence(如果您找不到Persistence选项卡, View> Tool Windows> Persistence)

    2. 在这里你可以右键点击名为模块的hibernate图标

    3. 转到Generate Persistence Mapping by database schema

    4. 现在我想你可以找到你的方式...

    5. 在一般设置中选择要使用的数据源,现在你可以做许多事情,添加与+符号的关系,改变
      的名称和类型,你可以看到你的数据源对象中的所有表格

    6. < pojo的属性等。
      注意:如果你得到一个错误,并且OK被禁用,可能是因为intelliJ为您的pojo找到的数据
      类型无效。只需将其更改为您需要的一个
      即可。

    更新:

    在IntelliJ 16中,此功能现已实现。
    执行此操作的步骤是:

    数据库查看上下文菜单

    脚本扩展

    生成POJO

    https://youtrack.jetbrains.com/oauth?state =%2Fissue%2FIDEA-66037


    How can I generate entity (POJO) from database model using IntelliJ IDEA 10. I create "Data source" in IntelliJ but I have not any idea how can I generate the POJO.

    解决方案

    The steps are simple but I guess its difficult since you are used to the eclipse interface (I would feel the same way if I had to do it in Eclipse)

    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!

    UPDATE:
    In IntelliJ 16 this feature in now implemented. The steps to do it are:
    Database view context menu
    Scripted Extensions
    Generate POJOs
    https://youtrack.jetbrains.com/oauth?state=%2Fissue%2FIDEA-66037

    这篇关于IntelliJ IDEA 10从DB模型生成实体(POJO)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆