Hi all!
I'm using hibernate-core 5.2.6.Final for querying Views from an Oracle-SQL Server (Oracle10gDialect).
I've generated both POJO and StaticMetaModel files.
In hibernate.cfg.xml I'm mapping to the POJO entity class.
I'm not allowed to post original company code, but the StaticMetaModel looks like:
Code:
@Generated(value = "org.hibernate.jpamodelgen.JPAMetaModelEntityProcessor")
@StaticMetamodel(MyEntity.class)
public abstract class MyEntity_ {
public static volatile SingularAttribute<MyEntity, String> someId;
public static volatile SingularAttribute<MyEntity, Long> someLong; // NUMBER(4)
}
I can query the view when adding a where-clause for
someId.
But when I additionally add someLong to the where-clause i get a NullpointerException.Code:
java.lang.NullPointerException
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.setParameter(CriteriaQueryTypeQueryAdapter.java:375)
at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.setParameter(CriteriaQueryTypeQueryAdapter.java:57)
.....
The query looks like this:
Code:
public Collection<MyEntity> readData(String id, long longValue) {
EntityManager em = this.getSession().getEntityManagerFactory().createEntityManager();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<MyEntity> q = cb.createQuery(MyEntity.class);
Root<MyEntity> root = q.from(MyEntity.class);
ParameterExpression<Long> pSomeLong = cb.parameter(Long.class);
q.where(cb.equal(root.get(MyEntity_.someLong), pSomeLong ));
ParameterExpression<String> pSomeId = cb.parameter(String.class);
q.where(cb.equal(root.get(MyEntity_.someId), pSomeId ));
TypedQuery<MyEntity> query = em.createQuery(q);
query.setParameter(pSomeId , id);
query.setParameter(pSomeLong , longValue); // crash happens here
return query.getResultList();
}
The exception occurs when I call
query.setParameter(pSomeLong , longValue).
Here is the POJO:
Code:
@Entity
@Table(name = "MY_ENTITY_VIEW", schema = "SOME_SCHEMA", catalog = "")
public class MyEntity implements java.io.Serializable {
/**
*
*/
private static final long serialVersionUID = -7508480021949722883L;
private Long someLong;
private String someId;
@Basic
@Column(name = "LONG_FIELD")
public Long getSomeLong() {
return someLong;
}
public void setSomeLong(Long someLong) {
this.someLong = someLong;
}
@Id
@Basic
@Column(name = "SOME_ID")
public String getSomeId() {
return someId;
}
public void setSomeId(String someId) {
this.someId = someId;
}
}
When debugging the Hibernate code i can see that
resolveParameterInfo returns a NullReference (CriteriaQueryTypeQueryAdapter):
Code:
@Override
@SuppressWarnings({ "unchecked" })
public <T> QueryImplementor<X> setParameter(Parameter<T> param, T t) {
entityManager.checkOpen( false );
final ExplicitParameterInfo parameterInfo = resolveParameterInfo( param ); // ---> returns null
if ( parameterInfo.isNamed() ) {
jpqlQuery.setParameter( parameterInfo.getName(), t );
}
else {
jpqlQuery.setParameter( parameterInfo.getPosition(), t );
}
return this;
}
Does anyone have an idea what's going wrong here?
Any hints welcome.
Thanks in advance.
Regards,
Jo