-
15. Re: Enum attributes in Entity Beans ...
mustaghattack Aug 24, 2005 6:59 AM (in response to epbernard)I get the following exception when I try to load an Entity which contain an enum field :
Exception in thread "main" java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=bruno/442, BranchQual=, localId=442] status=STATUS_NO_TRANSACTION; - nested throwable: (org.hibernate.PropertyAccessException: could not set a field value by reflection setter of org.wiskee.bd.entity.FicheTechnique.expositionMontee) at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:185) ... Caused by: org.hibernate.PropertyAccessException: could not set a field value by reflection setter of org.wiskee.bd.entity.FicheTechnique.expositionMontee at org.hibernate.property.DirectPropertyAccessor$DirectSetter.set(DirectPropertyAccessor.java:82) ...
Here is my entity bean code :@SuppressWarnings("serial") @Entity( access = AccessType.FIELD ) public class FicheTechnique implements Serializable { @Id( generate = GeneratorType.AUTO ) private int id; public String nom; ... public Exposition expositionMontee; ... }
and my enum look like this :public enum Exposition{ S, SSO, SO, OSO, O, ONO, NO, NNO, N, NNE, NE, ENE, E, ESE, SE, SSE }
So it's very basic !
Note : I'm using JBoss 4.0.2 with EJB 3 RC2
PS : enums are Serializable by nature ? Isn't it redundant to make them implements Serializable ? -
16. Re: Enum attributes in Entity Beans ...
epbernard Aug 25, 2005 12:05 PM (in response to epbernard)This case works fine on my test suite. There is something else in your code.
-
17. Re: Enum attributes in Entity Beans ...
mustaghattack Aug 26, 2005 7:40 AM (in response to epbernard)I found the problem !
In fact I need to reboot the JBoss server (4.0.2 with EJB 3.0 RC 2) if I make some change in my entity (and only do a redeploy).
You can run this example to reproduce the "bug" :
The entity :package org.test; import java.io.Serializable; import javax.persistence.AccessType; import javax.persistence.Entity; import javax.persistence.GeneratorType; import javax.persistence.Id; @SuppressWarnings("serial") @Entity( access = AccessType.FIELD ) public class EntiteTest implements Serializable { @Id( generate = GeneratorType.AUTO ) int id; public String nom; public EnumTest enumTest; // this attribute will be useful later ... // public EnumTest enumTest2; public int getId() { return id; } }
The Enum definition :package org.test; public enum EnumTest { BONJOUR, AUREVOIR, ADIEU }
A stateless session bean :package org.test; import java.util.ArrayList; import java.util.List; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import javax.persistence.Query; public @Stateless class GestionnaireEntiteTestBean implements GestionnaireEntiteTest { @PersistenceContext private EntityManager manager; public List< EntiteTest > getAllEntiteTest() { ArrayList< EntiteTest > entiteTests = new ArrayList< EntiteTest>(); Query q = manager.createQuery( "from EntiteTest"); for( Object o : q.getResultList()) { entiteTests.add( (EntiteTest)o); } return entiteTests; } public EntiteTest addEntiteTest( EntiteTest entite ) { manager.persist( entite ); return entite; } }
the remote interface :package org.test; import java.util.List; import javax.ejb.Remote; @Remote public interface GestionnaireEntiteTest { public List< EntiteTest > getAllEntiteTest(); public EntiteTest addEntiteTest( EntiteTest entite ); }
The persistence.xml file in my package :<entity-manager> <jta-data-source>java:/DefaultDS</jta-data-source> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.HSQLDialect" /> <property name="hibernate.hbm2ddl.auto" value="create-drop" /> </properties> </entity-manager>
I followed this step :
1. start JBoss with the previous version of the entity
2. the client will work fine
3. change the entity : add the enumTest2 attribute
4. redeploy the package
5. update the client
6. run again the client => the previous exception will appear ..
Is that normal ?
I checked the database (I'm using the Hypersonic default database), and there's no null field in the EntiteTest table.
When I reboot JBoss every thing is working fine ... -
18. Re: Enum attributes in Entity Beans ...
arikkfir Aug 27, 2005 8:45 AM (in response to epbernard)Hi,
This happens to me too. Restarting JBoss seems to make it ok, until I redeploy (even without any changes).
My stack trace is:
Exception in thread "main" javax.ejb.EJBException: null; CausedByException is:
exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of crm.model.customers.CustomerField.setType
at org.jboss.ejb3.tx.Ejb3TxPolicy.handleExceptionInOurTx(Ejb3TxPolicy.java:46)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:70)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:195)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:69)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:566)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:436)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:239)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:277)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:168)
org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of crm.model.customers.CustomerField.setType
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:209)
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:179)
at org.hibernate.persister.entity.AbstractEntityPersister.setPropertyValues(AbstractEntityPersister.java:3056)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:121)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:792)
at org.hibernate.loader.Loader.doQuery(Loader.java:690)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:221)
at org.hibernate.loader.Loader.doList(Loader.java:2001)
at org.hibernate.loader.Loader.list(Loader.java:1985)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:405)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:293)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:864)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:41)
at crm.services.customers.CustomersManagerImpl.findFields(CustomersManagerImpl.java:38)
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:585)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:99)
at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:32)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:66)
at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:134)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.tx.TxPropagationInterceptor.invoke(TxPropagationInterceptor.java:61)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:39)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.aspects.security.AuthenticationInterceptor.invoke(AuthenticationInterceptor.java:63)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.asynchronous.AsynchronousInterceptor.invoke(AsynchronousInterceptor.java:91)
at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:88)
at org.jboss.ejb3.stateless.StatelessContainer.dynamicInvoke(StatelessContainer.java:195)
at org.jboss.aop.Dispatcher.invoke(Dispatcher.java:107)
at org.jboss.aspects.remoting.AOPRemotingInvocationHandler.invoke(AOPRemotingInvocationHandler.java:69)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:566)
at org.jboss.remoting.ServerInvoker.invoke(ServerInvoker.java:436)
at org.jboss.remoting.transport.socket.ServerThread.processInvocation(ServerThread.java:239)
at org.jboss.remoting.transport.socket.ServerThread.dorun(ServerThread.java:277)
at org.jboss.remoting.transport.socket.ServerThread.run(ServerThread.java:168)
Caused by: net.sf.cglib.beans.BulkBeanException: crm.model.customers.FieldType
at crm.model.customers.CustomerField$$BulkBeanByCGLIB$$5a04b97c.setPropertyValues()
at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:206)
... 40 more
Caused by: java.lang.ClassCastException: crm.model.customers.FieldType
... 42 more -
19. Re: Enum attributes in Entity Beans ...
hurzeler Sep 1, 2005 3:33 AM (in response to epbernard)Do we have a solution for this yet?
I can definitly reproduce this as well.
Take care, Bernie -
20. Re: Enum attributes in Entity Beans ...
hurzeler Sep 5, 2005 3:21 AM (in response to epbernard)I can definitly reproduce this issue (same as arikkfir). Does anyone have a solution for this?
Cheers Bernie -
21. Re: Enum attributes in Entity Beans ...
jc7442 Sep 5, 2005 4:04 AM (in response to epbernard)I thought that I had that kind of problem. It was due to the fact that my enum does not implement Serializable.
-
22. Re: Enum attributes in Entity Beans ...
yuyong Dec 28, 2005 1:42 AM (in response to epbernard)"dsouza" wrote:
Ok, I tested it again for Oracle and it did work, however I did run into some other problems.
I have a cactus test suite that inserts/updates/deletes entities in the database to make sure they're working and that they have the appropriate permissions. So in order to test the use of enums in an entity I used one of my entity tests (for an entity that needs an enum).
Basically I have this line of code in my test suite:interfaceMessage.setMessageType(InterfaceMessageType.WARNING);
where InterfaceMessageType is my enum. If I change the line tointerfaceMessage.setMessageType(InterfaceMessageType.ERROR);
and redeploy without restarting JBOSS, I get the following exception:org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of entity.iface.InterfaceMessage.setMessageType at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:209) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:179) at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2981) ... Caused by: net.sf.cglib.beans.BulkBeanException: entity.enums.InterfaceMessageType at entity.iface.InterfaceMessage$$BulkBeanByCGLIB$$48beb320.setPropertyValues(<generated>) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:206) ... 84 more Caused by: java.lang.ClassCastException: entity.enums.InterfaceMessageType ... 86 more
If I restart JBOSS everything works fine (until I change the code again). I really have no idea why this is happening but I thought maybe something from mixing the latest hibernate cvs with the ejb 3 beta release, but then again I guess it's unlikely since hibernate handles the persistence. Any ideas of what might be causing this?
Another problem is that the latest cvs broke some of my other code. Maybe it's something that's really changed for good and I'm not up to date yet, but I'm getting the following exception:org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=brain/24, BranchQual=, localId=24] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.ClassCastException: java.util.ArrayList) java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=brain/24, BranchQual=, localId=24] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.ClassCastException: java.util.ArrayList) at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:185) at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:167) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:74) ...
Looks like some problem in using ArrayList in OneToMany or ManyToMany relationships. Just thought you should know in case it's a new bug or something. -
23. Re: Enum attributes in Entity Beans ...
wcydaip Jul 27, 2006 5:50 PM (in response to epbernard)"dsouza" wrote:
Ok, I tested it again for Oracle and it did work, however I did run into some other problems.
SOME SECURITY
I have a cactus test suite that inserts/updates/deletes entities in the database to make sure they're working and that they have the appropriate permissions. So in order to test the use of enums in an entity I used one of my entity tests (for an entity that needs an enum).
Basically I have this line of code in my test suite:interfaceMessage.setMessageType(InterfaceMessageType.WARNING);
where InterfaceMessageType is my enum. If I change the line tointerfaceMessage.setMessageType(InterfaceMessageType.ERROR);
and redeploy without restarting JBOSS, I get the following exception:org.hibernate.PropertyAccessException: exception setting property value with CGLIB (set hibernate.cglib.use_reflection_optimizer=false for more info) setter of entity.iface.InterfaceMessage.setMessageType at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:209) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValues(PojoEntityTuplizer.java:179) at org.hibernate.persister.entity.BasicEntityPersister.setPropertyValues(BasicEntityPersister.java:2981) ... Caused by: net.sf.cglib.beans.BulkBeanException: entity.enums.InterfaceMessageType at entity.iface.InterfaceMessage$$BulkBeanByCGLIB$$48beb320.setPropertyValues(<generated>) at org.hibernate.tuple.PojoEntityTuplizer.setPropertyValuesWithOptimizer(PojoEntityTuplizer.java:206) ... 84 more Caused by: java.lang.ClassCastException: entity.enums.InterfaceMessageType ... 86 more
If I restart JBOSS everything works fine (until I change the code again). I really have no idea why this is happening but I thought maybe something from mixing the latest hibernate cvs with the ejb 3 beta release, but then again I guess it's unlikely since hibernate handles the persistence. Any ideas of what might be causing this?
Another problem is that the latest cvs broke some of my other code. Maybe it's something that's really changed for good and I'm not up to date yet, but I'm getting the following exception:org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=brain/24, BranchQual=, localId=24] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.ClassCastException: java.util.ArrayList) java.lang.RuntimeException: org.jboss.tm.JBossRollbackException: Unable to commit, tx=TransactionImpl:XidImpl[FormatId=257, GlobalId=brain/24, BranchQual=, localId=24] status=STATUS_NO_TRANSACTION; - nested throwable: (java.lang.ClassCastException: java.util.ArrayList) at org.jboss.aspects.tx.TxPolicy.handleEndTransactionException(TxPolicy.java:185) at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:167) at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:74) ...
Looks like some problem in using ArrayList in OneToMany or ManyToMany relationships. Just thought you should know in case it's a new bug or something.