-->
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.  [ 4 posts ] 
Author Message
 Post subject: Enum / UserType / CGLIB problem
PostPosted: Wed Mar 31, 2004 10:45 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Hi.

I'm using an enumerated type representing a small number of user roles.

The enumerated class:
Code:

import java.io.Serializable;
import net.sf.hibernate.PersistentEnum;
import ks.rah.commons.Group;

public class InternalRole implements Serializable, PersistentEnum  {
   
    private final int code;
   
    private InternalRole(int code) {
        this.code = code;
    }
   
    public static final InternalRole USER = new InternalRole(0);
    public static final InternalRole POWERUSER = new InternalRole(1);
    public static final InternalRole ADMINISTRATOR = new InternalRole(2);

    public int toInt() { return code; }

    public static InternalRole fromInt(int code) {
        switch (code) {
            case 0: return USER;
            case 1: return POWERUSER;
            case 2: return ADMINISTRATOR;
            default: throw new RuntimeException("Unknown internal role");
        }
    }
}   


And I read posts about making this a UserType

Code:
public class InternalRoleType implements Serializable, net.sf.hibernate.UserType  {
   
   private static final Class CLAZZ = InternalRole.class;
    private static final int[] SQL_TYPES = new int[] { java.sql.Types.INTEGER };


    public InternalRoleType()
    {
    }

    public Class returnedClass()
    {
        return CLAZZ ;
    }

    public int[] sqlTypes()
    {
        return SQL_TYPES ;
    }

    public boolean isMutable()
    {
        return false;
    }

    public Object deepCopy( Object obj )
    throws net.sf.hibernate.HibernateException
    {
        return obj;
    }
   
    public boolean equals( Object obj1, Object obj2 )
    throws net.sf.hibernate.HibernateException
    {
        if( obj1 == obj2 ) return true;
        if( obj1 == null || obj2 == null ) return false;

        return ((InternalRole)obj1).equals( (InternalRole)obj2 );
    }
   
    public Object nullSafeGet( java.sql.ResultSet resultSet, String[] names, Object owner )
    throws net.sf.hibernate.HibernateException, java.sql.SQLException
    {
        Integer value = (Integer)Hibernate.INTEGER.nullSafeGet( resultSet, names[0] );

        try
        {
            if (value == null)
                return InternalRole.USER;
            else
                return InternalRole.fromInt( value.intValue() );
        }
        catch( Exception e )
        {

        }
        return InternalRole.USER;
    }
   
    public void nullSafeSet( java.sql.PreparedStatement preparedStatement, Object obj, int index )
    throws net.sf.hibernate.HibernateException, java.sql.SQLException
    {
        InternalRole level = (InternalRole) obj;
        Hibernate.INTEGER.nullSafeSet( preparedStatement, new Integer(level.toInt()), index );
    }
}


Mapping for the User class that contains this UserType (snippet)

Code:
..
<hibernate-mapping>
    <class
        name="ks.rah.radius.domain.User"
        table="MASTERUSER"
        dynamic-update="false"
        dynamic-insert="false"
    >
...
...
<property
            name="internalRole"
            type="ks.rah.radius.domain.model.InternalRoleType"
            update="true"
            insert="true"
            column="ROLEINTERNAL"
            not-null="false"
            unique="false"
        />
...
...



I'm using Spring framework 1.0 with Hibernate support and it all worked like a clockwork until I tried implementing the UserType, MySQL but I suspect there's something I'm overlooking in the code.


The exception I get is

Code:
Data access failure: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of ks.rah.radius.domain.User.setInternalRole; nested exception is net.sf.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of ks.rah.radius.domain.User.setInternalRole

and lots more....


Does anybody recognize this?

Sincerely,

/C


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 01, 2004 3:35 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Did you try what was asked
Quote:
set hibernate.cglib.use_reflection_optimizer=false for more info

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Cont..
PostPosted: Thu Apr 01, 2004 4:45 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Yes I did. It still tells me to do it, however.
I'm setting it to "false" in the by

Code:
<bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
      <property name="dataSource"><ref local="dataSource"/></property>
      <property name="mappingResources">
      <list>
         <value>ks/rah/radius/domain/User.hbm.xml</value>
         <value>ks/rah/radius/domain/Unit.hbm.xml</value>
         <value>ks/rah/radius/domain/Application.hbm.xml</value>
         <value>ks/rah/radius/domain/Role.hbm.xml</value>
         <value>ks/rah/radius/domain/Group.hbm.xml</value>
      </list>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">net.sf.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">false</prop>
            <prop key="hibernate.c3p0.max_size">15</prop>
            <prop key="hibernate.c3p0.min_size">2</prop>
            <prop key="hibernate.c3p0.timeout">5000</prop>
            <prop key="hibernate.c3p0.max_statements">100</prop>
            <prop key="hibernate.c3p0.validate">false</prop>
            <prop key="hibernate.cglib.use_reflection_optimizer">false</prop>
         </props>
      </property>
   </bean>


Here's the continuation of the stack printout

Code:
Caused by: net.sf.cglib.beans.BulkBeanException
        at ks.rah.radius.domain.User$$BulkBeanByCGLIB$$6edb0a79.setPropertyValues(<generated>)
        at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:204)
        ... 62 more
Caused by: java.lang.ClassCastException
        ... 64 more


Hibernate 2.1 final, MySQL 4.0.17, JDK 1.4.2

/C[/code]


Top
 Profile  
 
 Post subject: Cont
PostPosted: Thu Apr 01, 2004 9:58 am 
Regular
Regular

Joined: Wed Nov 26, 2003 6:22 am
Posts: 76
Location: Stockholm
Managed to set the optimizer to 'false'. So much more information didn't come out of it. Obviously there is some kind of mismatch, but where lies the code error????

Code:
15:57:04,125  WARN DispatcherServlet:413 - Handler execution resulted in exception - forwarding to resolved error view
org.springframework.orm.hibernate.HibernateSystemException: IllegalArgumentException occurred while calling setter of ks
.rah.radius.domain.User.internalRole; nested exception is net.sf.hibernate.PropertyAccessException: IllegalArgumentExcep
tion occurred while calling setter of ks.rah.radius.domain.User.internalRole
net.sf.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of ks.rah.radius.domain
.User.internalRole
        at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:68)
        at net.sf.hibernate.persister.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:222)
        at net.sf.hibernate.impl.SessionImpl.initializeEntity(SessionImpl.java:2174)
        at net.sf.hibernate.loader.Loader.doQuery(Loader.java:240)
        at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
        at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
        at net.sf.hibernate.loader.Loader.list(Loader.java:941)
        at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
        at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
        at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
        at org.springframework.orm.hibernate.HibernateTemplate$21.doInHibernate(HibernateTemplate.java:382)
        at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
        at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170)
        at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:375)
        at ks.rah.radius.logic.LogicFacadeImpl.findUser(LogicFacadeImpl.java:60)
        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:324)
        at org.springframework.aop.framework.AopProxyUtils.invokeJoinpointUsingReflection(AopProxyUtils.java:59)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
145)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:114)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:169)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:134)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:148)
        at $Proxy2.findUser(Unknown Source)
        at ks.rah.radius.web.form.LoginFormController.onSubmit(LoginFormController.java:88)
        at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:208)

        at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:
236)
        at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:119)
        at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java
:45)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:389)
        at org.springframework.web.servlet.FrameworkServlet.serviceWrapper(FrameworkServlet.java:339)
        at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:325)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2416)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
        at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
        at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:601)
        at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
        at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
        at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
        at java.lang.Thread.run(Thread.java:534)
Caused by: java.lang.IllegalArgumentException: argument type mismatch
        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:324)
        at net.sf.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:38)
        ... 64 more
[/code]


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

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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.