Hi,
when creating access group ,session attribute and Constraints are automatically created.
but in the Where Clause in session attribute, constraint isn’t created according to the name.how do I create it?
As following cord:-
@Component(“sampellisner_GroupEntityListener”)
public class GroupEntityListener implements BeforeInsertEntityListener {
@Inject
private Persistence persistence;
@Inject
private Metadata metadata;
@Inject
private UniqueNumbersAPI uniqueNumbers;
public static final String NAME = "sampellisner_GroupEntityListener";
@Override
public void onBeforeInsert(Group entity, EntityManager entityManager) {
SessionAttribute sessionAttribute = metadata.create(SessionAttribute.class);
sessionAttribute.setName("someNumber");
sessionAttribute.setStringValue(Long.toString(uniqueNumbers.getNextNumber(GroupEntityListener.NAME)));
sessionAttribute.setDatatype(IntegerDatatype.NAME);
sessionAttribute.setGroup(entity);
Constraint constraint = metadata.create(Constraint.class);
constraint.setEntityName("sampellisner$Teacher");
constraint.setOperationType(ConstraintOperationType.fromId(ConstraintOperationType.READ.getId()));
constraint.setCheckType(ConstraintCheckType.fromId(ConstraintCheckType.DATABASE.getId()));
constraint.setIsActive(true);
constraint.setGroup(entity);
entityManager.persist(sessionAttribute);
entityManager.persist(constraint);
}
}
Constraints Image:-