Reverse engineer DDL from JPA entities

后端 未结 8 1399
情歌与酒
情歌与酒 2020-12-08 05:13

I\'m playing around with some JPA stuff, changing the mappings to see how they\'re supposed to be etc. It\'s basic experimentation. However I can\'t find a tool that will si

8条回答
  •  囚心锁ツ
    2020-12-08 05:53

    I don't think there is an universal way of doing this with JPA, you have to directly use the underlying JPA implementation to achieve this.

    For Hibernate, there are several possibilities:

    • Use the method duffymo posted earlier, that makes Hibernate update the database schema automatically.
    • If you do not want that, you can use the hbm2ddl tool from Hibernate Tools (note: link sucks, but apparently their home page is a bit broken right now). You can use that to automatically generate database creation scripts from your JPA entities; there are also plugins for Maven and Ant that invoke hbm2ddl automatically.

    For EclipseLink (formerly Oracle TopLink, the JPA 2.0 RI) see Using EclipseLink JPA Extensions for Schema Generation. In principle it is very similar to Hibernate, although at first glance I don't see anything that could be used as a stand-alone utility for creating a DB script.

    Other JPA implementations (BEA/Oracle Kodo, Apache OpenJPA) probably have their own specific methods of achieving this.

提交回复
热议问题