hibernate/jpa元模型类不包含所有字段 [英] hibernate/jpa metamodel classes do not include all fields
问题描述
我正在使用maven开发并在eclipse中进行编辑的hibernate/jpa应用程序遇到此超级烦人的问题.
I am having this super irritating issue with my hibernate/jpa app I'm developing using maven and editing in eclipse.
我在属性">编译器">注释处理"中设置了目标/元模型位置,并且一切正常,除了一个类,其中元模型类仅包含id.
I have my target/metamodel location set up in Properties > compiler > annotation processing, and it's all working fine, except for one class, where the metamodel class only contains the 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中遇到编译错误,试图在该DAO中尝试使用用户名/pw获得用户,并且这些字段在metamodel类中不存在.
This issue only occurs in the User class, all other classes are fine. I am getting compile errors in my DAO where I try to get a user with username/pw, and those fields do not exist in the metamodel class.
有什么想法会导致这种情况吗? 在linux上工作,编译器设置为1.8. 谢谢
Any ideas what would cause this? Working on linux, compiler set to 1.8. thanks
最后我通过在persistence.xml中为实体添加条目来解决它
I ended up solving it by adding an entry for the entity in persistence.xml
<class>com.mypack.model.User</class>
我经历了创建实体以及执行id保存,更新,删除和获取id函数的过程,而没有persistence.xml条目.我想我从一些开始,发现我不需要它们,并注释掉了它们.
I had gone thru the process of creating the entity and doing crud save, update, delete, and get by id functions, without the persistence.xml entries. I think I started with a few, found I didn't need them and commented them out.
现在看到,当我尝试创建criteriabuilder/root/query等时,遇到了这个问题.将实体添加到persistence.xml似乎已经解决了它.
Seeing now that when I try to create a criteriabuilder/root/query, etc, I run into that issue. Adding the entity to persistence.xml seems to have resolved it.
推荐答案
我认为这可能是Dali Generator的错.我通过常规的Maven插件尝试了hibernate-jpamodelgen,它工作正常.
I think it may be Dali generator's fault. I tried with hibernate-jpamodelgen through regular maven plugin and it works fine.
我建议您做同样的事情:它可以工作,项目中的每个人都会从中受益,您不必提交生成的源代码,也不必告诉每个人以相同的方式配置Eclipse.
I suggest you do the same: it works, and everyone working on the project will benefit from it, you won't have to commit generated sources or tell everyone to configure Eclipse in the same way.
<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>
这篇关于hibernate/jpa元模型类不包含所有字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!