-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Error when using @ENUMERATED annotation with ORDINAL type
PostPosted: Wed Feb 18, 2009 1:01 pm 
Newbie

Joined: Wed Feb 18, 2009 5:32 am
Posts: 1
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.