簡體   English   中英

hibernate/jpa 元模型類不包括所有字段

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM