0
我有一個屬性(MetaData中的creationTimestamp),我註釋了加載懶惰的屬性。不,我需要它爲一個實體加載渴望。我試圖與取圖沒有成功。有沒有像我可以用來在查詢中獲取它的JOIN FETCH功能?JPA 2.1渴望獲取屬性
我正在使用Wildfly捆綁休眠。
當我嘗試使用提取圖獲取它時,我得到了一個例外,即hibernate無法找到id字段。該字段位於實體基礎(受保護)中。
@NamedQueries({ @NamedQuery(name = ChatMessage.FIND_BY_CHAT_TIME, query = "SELECT m FROM ChatMessage m "
+ "WHERE m.chat=:chat "
+ "AND m.creationTimestamp > :index ORDER BY m.creationTimestamp") })
@NamedEntityGraph(
name = ChatMessage.GRAPH_FETCH_ALL,
attributeNodes = {@NamedAttributeNode("id"), @NamedAttributeNode("player"), @NamedAttributeNode("text"), @NamedAttributeNode("creationTimestamp")}
)
public class ChatMessage extends EntityBase {
@MappedSuperclass
public abstract class EntityBase extends MetaData {
private static final long serialVersionUID = -5579667581450362176L;
public static final String FETCH_GRAPH_HINT = "javax.persistence.fetchgraph";
@Id
@Column(length = 36)
protected String id = java.util.UUID.randomUUID().toString();
@MappedSuperclass
public class MetaData implements Serializable {
private static final long serialVersionUID = 8870539357817188030L;
@Version
private long version;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false, updatable = false)
@Basic(fetch=FetchType.LAZY)
protected Calendar creationTimestamp;
@Temporal(TemporalType.TIMESTAMP)
@Column(nullable = false)
@Basic(fetch=FetchType.LAZY)
private Calendar updateTimestamp;
導致這個例外:
Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [id] on this ManagedType [ChatMessage]
at org.hibernate.jpa.internal.metamodel.AbstractManagedType.checkNotNull(AbstractManagedType.java:144)
at org.hibernate.jpa.internal.metamodel.AbstractManagedType.getDeclaredAttribute(AbstractManagedType.java:137)
at org.hibernate.jpa.graph.internal.EntityGraphImpl.resolveAttribute(EntityGraphImpl.java:139)
at org.hibernate.jpa.graph.internal.AbstractGraphNode.buildAttributeNode(AbstractGraphNode.java:119)
at org.hibernate.jpa.graph.internal.AbstractGraphNode.addAttribute(AbstractGraphNode.java:114)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.applyNamedAttributeNodes(EntityManagerFactoryImpl.java:279)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.applyNamedEntityGraphs(EntityManagerFactoryImpl.java:266)
at org.hibernate.jpa.internal.EntityManagerFactoryImpl.<init>(EntityManagerFactoryImpl.java:173)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:865)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl$4.perform(EntityManagerFactoryBuilderImpl.java:843)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.withTccl(ClassLoaderServiceImpl.java:399)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:842)
at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:73)
有沒有一種方法來獲取像抓取連接的屬性?或者我必須以另一種方式引用抓取圖嗎?
最好的問候, 米