如何阻止 eclipse 从表中自动创建 JPA 实体?

How do you stop eclipse from automatically creating JPA entities from tables?

我在 eclipse 中有一个 JPA 项目,有些东西一直在同步数据库表和实体。问题是创建的实体以下划线 ("_.java") 结尾。我已经从模式中手动创建了实体,因此会导致重复的实体,然后版本控制会选择它们并希望将它们添加到存储库等。

如何告诉 eclipse 不生成实体,或者生成实体但不带下划线?

那些xxx_.java文件是元模型classes,它们是必需的,由框架自动生成,不应该干扰你的工作,你为什么要删除它们?

正如this site所说:

This metamodel is important in 2 ways.

  • First, it allows providers and frameworks a generic way to deal with an application's domain model.
  • Second, from an application writer's perspective, it allows very fluent expression of completely type-safe criteria queries, especially the Static Metamodel approach.

并且:

  • For each managed class X in package p, a metamodel class X_ in package p is created.

  • The name of the metamodel class is derived from the name of the managed class by appending "_" to the name of the managed class.

对于您所写的内容,一切似乎都很正常。重复的 class 和 _ 是框架所必需的,您可以简单地忽略它们。您也应该阅读 this site 以获取更多信息。

但是如果您不想将这些文件添加到您的存储库中,则有一些方法可以在您必须提交时排除某些文件,具体取决于存储库系统(如 git,使用 .gitignore 文件).