JPA的Java code代 [英] JPA java code generation

查看:152
本文介绍了JPA的Java code代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我专门找JPA code生成技术

I am specifically looking for JPA code generation technique

首先,什么是所有的项目可能产生的JPA标准code? (如HibernateTools)

First, what are all the project could generate JPA compliant code? (Eg. HibernateTools)

第二,我也想定制code生成工具,因为它要符合我们的企业标准。

Second, I would also like to customize the code generation utility, as it has to compliant to our corporate standards.

如果不是,那么所有可用的使用反射来生成Java code中的框架?所以我可以从头开始编写。

If not, what are all the framework available to generate java code using reflection? so I can write from scratch.

请注意:我使用了Eclipse生成JPA code和重构它多次,以使其符合

Note: I used eclipse to generate JPA code and refactor it repeatedly to make it compliant.

推荐答案

我也有苦衷理解的问题,但我会尝试重组:

I also have difficulties understanding the question, but I'll try to rephrase:


  • 您有很多在DB数据,并想通过JPA访问它

  • 您不想手动编写的类访问不同的数据块/表

  • 目前,所有/大部分的模型类是在Eclipse中生成的

  • 这些模型有JPA注释

  • 模型类(或批注),不按企业标准

当你说JPA的Java code一代,我理解产生从提供的DB连接JPA注解模型类。大多数框架通常把这种现象称为逆向工程。

When you say "JPA java code generation", I understand generating JPA annotated model classes from a supplied DB connection. Most frameworks often refer to this as reverse engineering.

现在你有两个问题:


  1. 可以推荐什么code发生器产生的JPA注解的类?

  2. 是否可以自定义这些框架的输出,以及以何种方式?

要回答第一个问题:

  • Hibernate Tools - already mentioned in the question, but I prefer this one
  • EclipseLink
  • Netbeans

我真的很喜欢Netbeans的code一代,特别是如果你显示结果的人不熟悉JPA。

I really like the Netbeans code generation, especially if you show the results to someone not familiar with JPA.

在定制化水平,我只能分享我的经历与Hibernate工具。特别是对重复性的结果,尝试使用基于Ant任务。您可以轻松一些目标添加到您的构建和code一代可以在两个层面进行:

At the level of customization I can only share the experience I had with Hibernate Tools. Especially for reproducible results, try to use the ant-based tasks. You can easily add some targets to your build and code generation can be done at two levels:

  • Configure exporters using properties
  • Provide custom freemarker templates

随着模板,你应该能够覆盖大多数的企业标准。看看到 POJO 休眠工具包的目录。定制code一代最简单的方法是复制和调整模板,并让它们在用于创建的POJO蚂蚁任务休眠-tools.jar中之前付诸表决。

With the templates you should be able to cover most of the corporate standards. Look into the pojo directory of the hibernate-tools package. The easiest way to customize the code generation is to copy and adapt the templates and have them put before the hibernate-tools.jar in the ant task used to create the pojos.

作为另一条评论已经指出,这可能是很难事后修改生成的code。我希望下面的提示可以帮助您:

As already pointed out in another comment, it might be difficult to modify the generated code afterwards. I hope the following tips can help you:


  • 尝试以生成和定制化的源文件在不同的文件夹中分离出来。

  • 考虑使用 @MappedSuperclass而您可能希望在手动步骤,以适应课程。

这篇关于JPA的Java code代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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