Hi
Hibernate version: 3.3.1.GA
Name and version of the database you are using: Oracle 10g
My Entity class is like this:
Code:
@Entity
@Table(name="PUBLICATION")
public class Publication extends Message
{
private static final long serialVersionUID = 1L;
/** Identyfikator */
@Id
@Generated
private Integer id;
/**
* Status publikacji
* @see pl.nbp.portal.entity.common.PublicationStatus
*/
@Column(name="STATUS")
@Enumerated(EnumType.ORDINAL)
private PublicationStatus status;
/**
* Gettery i settery
*/
public Publication(){
}
public Integer getId() {
return id;
}
public void setIdStatus(Integer id) {
this.id = id;
}
public PublicationStatus getStatus() {
return status;
}
public void setStatus(PublicationStatus status) {
this.status = status;
}
}
Enum class code:
Code:
public enum PublicationStatus {
PUBLISHED ("Opublikowana"),
NEW ("Nowa"),
CANCELLED ("Anulowana");
/** Opis enum'a */
private String description;
/** Konstruktor */
private PublicationStatus(String description) {
this.description = description;
}
/** Getter */
public String getDescription() {
return description;
}
}
When i make a query:
Code:
public List<Publication> commonPublicationList(){
Query query = em.createQuery("SELECT p FROM Publication p WHERE p.status =:publicationStatus");
query.setParameter("publicationStatus", PublicationStatus.PUBLISHED);
List<Publication> list = query.getResultList();
return list;
}
}
I've got an error
Full stack trace of any exception that occurs: Code:
Caused by: javax.ejb.EJBTransactionRolledbackException: EJB Exception: ; nested exception is: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: could not execute query
at weblogic.ejb.container.internal.BaseLocalObject.handleSystemException(BaseLocalObject.java:794)
at weblogic.ejb.container.internal.BaseLocalObject.postInvoke1(BaseLocalObject.java:486)
at weblogic.ejb.container.internal.BaseLocalObject.postInvokeTxRetry(BaseLocalObject.java:424)
at pl.nbp.portal.ejb.publication.PublicationDAOImpl_tjn7ik_PublicationDAOImpl.commonPublicationList(PublicationDAOImpl_tjn7ik_PublicationDAOImpl.java:84)
at pl.nbp.portal.ejb.publication.CommonPublicationFacadeBean.commonPublicationList(CommonPublicationFacadeBean.java:45)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.bea.core.repackaged.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:281)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:187)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:154)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.jee.spi.MethodInvocationVisitorImpl.visit(MethodInvocationVisitorImpl.java:15)
at weblogic.ejb.container.injection.EnvironmentInterceptorCallbackImpl.callback(EnvironmentInterceptorCallbackImpl.java:54)
at com.bea.core.repackaged.springframework.jee.spi.EnvironmentInterceptor.invoke(EnvironmentInterceptor.java:30)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:126)
at com.bea.core.repackaged.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:114)
at com.bea.core.repackaged.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:176)
at com.bea.core.repackaged.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:210)
When i use
Code:
Query query = em.createQuery("SELECT p FROM Publication p WHERE p.status =:publicationStatus");
query.setParameter("publicationStatus", PublicationStatus.PUBLISHED.ordinal());
List<Publication> list = query.getResultList();
then there isn't any errors.
Please tell me: should i use
ordinal() function for enum parameter when i use ORDINAL enum type in query?
Thanks for help
Regards, Piotr