[英]hibernate/jpa metamodel classes do not include all fields
我正在使用 maven 开发并在 eclipse 中编辑我的 hibernate/jpa 应用程序时遇到了这个超级恼人的问题。
我在“属性”>“编译器”>“注释处理”中设置了我的目标/元模型位置,并且一切正常,除了一个类,其中元模型类仅包含 id。
这是实体:
@Entity
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private int id;
private String username;
private String password;
@Transient
private Authorization authorization;
// getters/setters omitted, but I do have them in the entity class
}
这是元模型类
@Generated(value="Dali", date="2019-06-22T11:49:45.797-0400")
@StaticMetamodel(User.class)
public class User_ {
public static volatile SingularAttribute<User, Integer> id;
}
此问题仅发生在 User 类中,所有其他类都可以。 我在我的 DAO 中遇到编译错误,我尝试使用用户名/密码获取用户,而这些字段在元模型类中不存在。
任何想法会导致这种情况? 在 linux 上工作,编译器设置为 1.8。 谢谢
我最终通过在persistence.xml中为实体添加一个条目来解决它
<class>com.mypack.model.User</class>
我已经完成了创建实体和执行 crud 保存、更新、删除和通过 id 函数获取的过程,没有 persistence.xml 条目。 我想我从一些开始,发现我不需要它们并将它们注释掉。
现在看到当我尝试创建一个标准构建器/根/查询等时,我遇到了这个问题。 将实体添加到 persistence.xml 似乎已经解决了它。
我想可能是大理发电机的问题。 我通过常规的 maven 插件尝试使用 hibernate-jpamodelgen,它工作正常。
我建议您也这样做:它有效,并且每个参与该项目的人都将从中受益,您不必提交生成的源代码或告诉每个人以相同的方式配置 Eclipse。
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
<compilerArguments>
<processor>org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor</processor>
</compilerArguments>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jpamodelgen</artifactId>
<version>5.4.3.Final</version>
</dependency>
</dependencies>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.