You need to put the @Optional annotation on your method parameters. Vennlig hilsen Webstep AS
Ronnie Nessa | Seniorkonsulent Tlf: +47 970 69 512 | [email protected] Den 24. mars 2011 kl. 13:17 skrev Dag Blakstad <[email protected]>: > Hi! > > I have this [pseudocode] that fails > > @Mixins(HasMainImageMixin.class) > public interface HasMainImage { > > Attachment mainImage(); > > void changedMainImage(Attachment attachment); > } > > public class HasMainImageMixin implements HasMainImage { > > interface PrivateState { > @Optional Association<Attachment> attachment(); > } > > @This PrivateState state; > > public void changedMainImage(Attachment attachment) { > if (attachment == null) { > state.set(null); > } > } > } > > @Mixins(HasMainImage.class) > public interface TestEntity extends EntityComposite, HasMainImage { > } > > The following test fails > @Test > public void testRemoveMainImage() throws Exception { > try { > EntityBuilder<TestEntity> testEntityEntityBuilder = > uow.newEntityBuilder(TestEntity.class, "test1"); > Attachment attachment = createAttachment(); > entity.changedMainImage(attachment); > > entity.changedMainImage(null); > } finally { > if (uow.isOpen()) > uow.discard(); > } > } > > The error is > org.qi4j.api.constraint.ConstraintViolationException: Constraint violation in > 88a8fa8e-6bee-4395-898f-d34fb41560dd-0.no.webstep.retrade.rpm.server.attachment.HasMainImageMixinTest$TestEntity > for method changedMainImage with constraint "not optional(param1)", for > value 'null' > > When the association attachment is annotated with @Optional it should be > possible to unset it somehow. Am I missing something, or could it be a bug? > > Best Regards, > Dag > > _______________________________________________ > qi4j-dev mailing list > [email protected] > http://lists.ops4j.org/mailman/listinfo/qi4j-dev _______________________________________________ qi4j-dev mailing list [email protected] http://lists.ops4j.org/mailman/listinfo/qi4j-dev

