【问题标题】:hibernate/jpa metamodel classes do not include all fieldshibernate/jpa 元模型类不包括所有字段
【发布时间】:2019-06-22 16:39:44
【问题描述】:

我正在使用 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 似乎已经解决了它。

【问题讨论】:

    标签: java hibernate jpa


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2011-12-09
      • 2016-08-13
      • 1970-01-01
      • 2012-05-10
      • 1970-01-01
      • 2012-04-23
      • 1970-01-01
      • 2021-12-22
      • 2020-03-06
      相关资源
      最近更新 更多