Can the community commons clone function not handle autonumbers?

1
When I use the community commons clone function I get an error when there is a autonumber in the object. Or am I misreading the error? I thought this was already fixed. I can use the deepclone but I do not need the associations and that is just a boolean in the clone function and something you need to specify in the deepclone (and with a lot of references a lot of work). Regards, Ronald An error has occurred while handling the request. [User 'med1' with session id '6958168c-1430-461d-8018-bd81c0fde268' and roles 'Medewerker'] -------- lg: com.mendix.core.CoreRuntimeException: java.lang.UnsupportedOperationException: Autonumber value can not be set manually. at Declaratie.Declaratie_Kopieren (JavaAction : 'Call 'Clone'') at Declaratie.Declaratie_Opslaan_en_Kopieren (SubMicroflow : 'Call 'Declaratie_Kopieren'') Advanced stacktrace: at mx.a(SourceFile:185) Caused by: com.mendix.core.CoreException: com.mendix.core.CoreRuntimeException: java.lang.UnsupportedOperationException: Autonumber value can not be set manually. at com.mendix.core.Core.execute(SourceFile:232) Caused by: com.mendix.core.CoreRuntimeException: java.lang.UnsupportedOperationException: Autonumber value can not be set manually. at hE.b(SourceFile:218) Caused by: java.lang.UnsupportedOperationException: Autonumber value can not be set manually. at com.mendix.core.objectmanagement.member.MendixAutoNumber.setValue(SourceFile:58) at com.mendix.core.objectmanagement.member.MendixAutoNumber.setValue(SourceFile:14) at ij.setValue(SourceFile:232) at ii.setValue(SourceFile:270) at communitycommons.ORM.cloneObject(ORM.java:249) at communitycommons.actions.Clone.executeAction(Clone.java:43) at communitycommons.actions.Clone.executeAction(Clone.java:25) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:457) at hE.b(SourceFile:207) at com.mendix.core.Core.execute(SourceFile:226) at ln.a(SourceFile:69) at mx.a(SourceFile:72) at mw.a(SourceFile:151) at mw.executeAction(SourceFile:98) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:457) at hE.b(SourceFile:207) at com.mendix.core.Core.executeSync(SourceFile:203) at lo.a(SourceFile:60) at mx.a(SourceFile:72) at mw.a(SourceFile:151) at mw.executeAction(SourceFile:98) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:457) at hE.b(SourceFile:207) at com.mendix.core.Core.execute(SourceFile:226) at gp.execute(SourceFile:186) at jd.a(SourceFile:319) at com.mendix.externalinterface.connector.RequestDispatching$Worker.a(SourceFile:170) at com.mendix.externalinterface.connector.RequestDispatching$Worker$a.a(SourceFile:161) at com.mendix.externalinterface.connector.RequestDispatching$Worker$a.apply(SourceFile:160) at akka.actor.Actor$class.apply(Actor.scala:545) at com.mendix.externalinterface.connector.RequestDispatching$Worker.apply(SourceFile:156) at akka.actor.LocalActorRef.invoke(ActorRef.scala:910) at akka.dispatch.MessageInvocation.invoke(MessageHandling.scala:25) at akka.dispatch.ExecutableMailbox$class.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:223) at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$4.processMailbox(ExecutorBasedEventDrivenDispatcher.scala:123) at akka.dispatch.ExecutableMailbox$class.run(ExecutorBasedEventDrivenDispatcher.scala:195) at akka.dispatch.ExecutorBasedEventDrivenDispatcher$$anon$4.run(ExecutorBasedEventDrivenDispatcher.scala:123) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) at akka.dispatch.MonitorableThread.run(ThreadPoolBuilder.scala:192) [EDIT] Using the deepclone function I get this error: java.lang.StackOverflowError at org.apache.commons.pool.impl.GenericObjectPool$Latch.<init>(GenericObjectPool.java:1860) at org.apache.commons.pool.impl.GenericObjectPool$Latch.<init>(GenericObjectPool.java:1860) at org.apache.commons.pool.impl.GenericObjectPool.borrowObject(GenericObjectPool.java:1060) at org.apache.commons.dbcp.PoolingDataSource.getConnection(PoolingDataSource.java:106) Anybody a guess why this is happening? I need to skip 20 plus references, but an error in the string should not result in a stack overflow. [EDIT2] Now even more errors. I think I will file bug report. java.lang.NoClassDefFoundError: communitycommons/ORM at communitycommons.actions.Clone.executeAction(Clone.java:43) at communitycommons.actions.Clone.executeAction(Clone.java:25) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:457) at hE.b(SourceFile:207) at com.mendix.core.Core.execute(SourceFile:226) at ln.a(SourceFile:69) at mx.a(SourceFile:72) at mw.a(SourceFile:151) at mw.executeAction(SourceFile:98) at com.mendix.systemwideinterfaces.core.UserAction.execute(SourceFile:57) at com.mendix.core.actionmanagement.CoreAction.call(SourceFile:457) at hE.b(SourceFile:207) at com.mendix.core.Core.executeSync(SourceFile:203) at lo.a(SourceFile:60) at mx.a(SourceFile:72)
asked
3 answers
4

This is a solution in the ORM.java file. Replace the existing method with

public static Boolean cloneObject(IContext c, IMendixObject source,
            IMendixObject target, Boolean withAssociations)
    {
        Map<String, ? extends IMendixObjectMember<?>> members = source.getMembers(c);

        for(String key : members.keySet()) { 
            IMendixObjectMember<?> m = members.get(key);
            if (m.isVirtual())
                continue;
            if (m instanceof MendixAutoNumber)
                continue;
            if (withAssociations || ((!(m instanceof MendixObjectReference) && !(m instanceof MendixObjectReferenceSet))))
                target.setValue(c, key, m.getValue(c));
        }
        return true;
    }
answered
4

Just checked it, this was fixed for deepClone, but not for normal clone.

A workaround is to change ORM.java line 242 from

if (m.isVirtual())

to

if (m.isVirtual() || m instanceof MendixAutoNumber)

I'll make sure it is part of the next release as well.

answered
0

We ran into this problem today, we had to enhance the java action adding the a list of member names to exclude. This ensured it skipped the Autonumber.

answered