hibernate / jpa元模型类不包含所有字段

时间:2019-06-22 16:39:44

标签: java hibernate jpa

我正在使用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中遇到编译错误,试图在该DAO中尝试使用用户名/ pw获得用户,并且这些字段在metamodel类中不存在。

任何想法会导致什么? 在Linux上工作,编译器设置为1.8。 谢谢

更新

最后我通过在persistence.xml中为实体添加条目来解决它

<class>com.mypack.model.User</class>

我已经经历了创建实体以及执行id保存,更新,删除和获取id函数的过程,而没有persistence.xml条目。我想我是从一些开始的,发现我不需要它们并注释掉它们。

现在看到,当我尝试创建criteriabuilder / root / query等时,遇到了这个问题。将实体添加到persistence.xml似乎已经解决了它。

1 个答案:

答案 0 :(得分:0)

我认为这可能是大理发电机的错。我通过常规的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>