EclipseLink中的JPA静态元模型类在访问属性时抛出NullPointerException
我对EclipseLink中生成的静态元模型类有一个问题。 在我的项目中,我首先使用以下方法生成为实体分类的静态元模型: 1) org.hibernate.jpamodelgen.jpametamodelenticyprocessor和IntelliJ IDEA 这些类已生成为:目标/生成源 然后,我尝试使用这种Hibernate生成的元模型类(如下所示)和EclipseLink(嵌入GlassFish),但包含元模型属性引用的代码行抛出NullPointerException异常:EclipseLink中的JPA静态元模型类在访问属性时抛出NullPointerException,jpa,intellij-idea,eclipselink,criteria-api,metamodel,Jpa,Intellij Idea,Eclipselink,Criteria Api,Metamodel,我对EclipseLink中生成的静态元模型类有一个问题。 在我的项目中,我首先使用以下方法生成为实体分类的静态元模型: 1) org.hibernate.jpamodelgen.jpametamodelenticyprocessor和IntelliJ IDEA 这些类已生成为:目标/生成源 然后,我尝试使用这种Hibernate生成的元模型类(如下所示)和EclipseLink(嵌入GlassFish),但包含元模型属性引用的代码行抛出NullPointerException异常: Sing
SingularAttribute<Employee, String> descriptionAttr = Employee_.description;
predicates.add(criteriaBuilder.like(employee.get(descriptionAttr), "%" + description + "%"));
这样,我想将Hibernate生成的类与Jboss一起使用,将EclipseLink生成的类与EclipseLink一起使用
4) 只有在WilfFly/Hibernate上运行,而不是在GlassFish/EclipseLink上运行时,这种配置才有效。这里是NullPointerException
5) 在persistence.xml中,我为一个持久化单元使用了这样的属性,生成了更多的over-eclipseelink
<property name="eclipselink.canonicalmodel.subpackage" value="metamodel" />
-我正在检查EclipseLink来源:
public <Y> Path<Y> get(SingularAttribute<? super X, Y> att){
if (att.getPersistentAttributeType().equals(
PersistentAttributeType.BASIC)) {
return new PathImpl<Y>(
this, this.metamodel, att.getBindableJavaType(),
this.currentNode.get(att.getName()), att);
} else {
Class<Y> clazz = att.getBindableJavaType();
Join join = new JoinImpl<X, Y>(
this, this.metamodel.managedType(clazz),
this.metamodel, clazz,
this.currentNode.get(att.getName()), att);
this.joins.add(join);
return join;
}
}
publicpath-get(SingularAttribute我知道这是一张旧票,但我仍然想让你们知道我们是如何解决这个问题的。尤其是最后一个nullpointer异常
问题是,当您第一次使用Criteriabuilder时,没有加载entitimanager。
要解决此问题,可以在persistence.xml中设置以下内容
<property name="eclipselink.deploy-on-startup" value="true" />
即使使用2.7.4
,我仍然面临这个问题
我对AttributeProxyImpl.java
中的以下方法非常好奇
public synchronized Attribute<X, T> getAttribute(){
if (attribute == null){
for (WeakReference<EntityManagerFactoryImpl> factoryRef: factories){
EntityManagerFactoryImpl factory = factoryRef.get();
if (factory != null){
factory.getDatabaseSession();
} else {
factories.remove(factoryRef);
}
}
}
return attribute;
}
公共同步属性getAttribute(){
if(属性==null){
对于(WeakReference factoryRef:工厂){
EntityManagerFactoryImpl工厂=factoryRef.get();
如果(工厂!=null){
getDatabaseSession();
}否则{
工厂。移除(factoryRef);
}
}
}
返回属性;
}
设置属性
字段的部分在哪里?问题可能出现在初始化失败的规范元模型中。
您可以调查您的eclipselink日志以检查以下内容:
Could not load the field named [...] on the class [...]
IllegalArgumentException: Can not set static ... field ... to ...
在我修复初始化后,NPE就消失了。我面临着完全相同的问题。我们是否对此有问题进行了跟踪?而且6.5.0
没有这个问题。也许2.7.0
引入了这个问题。哦,上帝,我仍然在2.7.4
中看到了这个问题。下面的答案可能是这个问题的解决方案:@Michal Zio兄弟,你找到解决办法了吗?
public <Y> Path<Y> get(SingularAttribute<? super X, Y> att){
if (att.getPersistentAttributeType().equals(
PersistentAttributeType.BASIC)) {
return new PathImpl<Y>(
this, this.metamodel, att.getBindableJavaType(),
this.currentNode.get(att.getName()), att);
} else {
Class<Y> clazz = att.getBindableJavaType();
Join join = new JoinImpl<X, Y>(
this, this.metamodel.managedType(clazz),
this.metamodel, clazz,
this.currentNode.get(att.getName()), att);
this.joins.add(join);
return join;
}
}
<property name="eclipselink.deploy-on-startup" value="true" />
public synchronized Attribute<X, T> getAttribute(){
if (attribute == null){
for (WeakReference<EntityManagerFactoryImpl> factoryRef: factories){
EntityManagerFactoryImpl factory = factoryRef.get();
if (factory != null){
factory.getDatabaseSession();
} else {
factories.remove(factoryRef);
}
}
}
return attribute;
}
Could not load the field named [...] on the class [...]
IllegalArgumentException: Can not set static ... field ... to ...