I'm trying out the traits feature and I'm having some problems. I'm preparing
simple Monkeys and Bananas example with existing classes that I want to add traits, but
when I try adding a trait (either declared in DRL or as a static interface) I'm
getting an exception thrown from the call to don(). Here's the code:
declare HungryMonkey
@format(trait)
end
rule "foo"
when
monkey : Monkey( )
then
HungryMonkey hm = don(monkey, HungryMonkey.class);
end
And the exception thrown:
Exception in thread "main" Exception executing consequence for rule
"foo" in org.gregcode.mnb: org.drools.RuntimeDroolsException: Field/method
'attachment' not found for class 'org.gregcode.mnb.MonkeyWrapper'
at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1101)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1029)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1251)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:709)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:673)
at org.gregcode.mnb.Main.main(Main.java:49)
Caused by: org.drools.RuntimeDroolsException: Field/method 'attachment' not found
for class 'org.gregcode.mnb.MonkeyWrapper'
at
org.drools.base.ClassFieldAccessorFactory.getClassFieldWriter(ClassFieldAccessorFactory.java:199)
at
org.drools.base.ClassFieldAccessorCache$CacheEntry.getWriteAccessor(ClassFieldAccessorCache.java:187)
at
org.drools.base.ClassFieldAccessorCache.getWriteAcessor(ClassFieldAccessorCache.java:116)
at org.drools.base.ClassFieldAccessorStore.wire(ClassFieldAccessorStore.java:424)
at org.drools.base.ClassFieldAccessorStore.getAccessor(ClassFieldAccessorStore.java:216)
at
org.drools.factmodel.traits.TraitFactory.buildWrapperClassDefinition(TraitFactory.java:340)
at org.drools.factmodel.traits.TraitFactory.getCoreWrapper(TraitFactory.java:310)
at org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:493)
at org.drools.base.DefaultKnowledgeHelper.don(DefaultKnowledgeHelper.java:522)
at
org.gregcode.mnb.Rule_foo_3c2199da53c4480ea0ec7b3d1c4781b5.defaultConsequence(Rule_foo_3c2199da53c4480ea0ec7b3d1c4781b5.java:7)
at
org.gregcode.mnb.Rule_foo_3c2199da53c4480ea0ec7b3d1c4781b5DefaultConsequenceInvokerGenerated.evaluate(Unknown
Source)
at
org.gregcode.mnb.Rule_foo_3c2199da53c4480ea0ec7b3d1c4781b5DefaultConsequenceInvoker.evaluate(Unknown
Source)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1091)
"MonkeyWrapper" is not in my code, so I'm assuming it's generated. I
also tried creating a HungryMonkey and HungryMonkeyImpl interface/class pair like the
Scholar and ScholarImpl from the traits example, but the same exception happened. Any
clues?