Skip to content

Incoming Association

Stefan Meyer edited this page Jul 28, 2012 · 3 revisions

Consider an class Person with a field of class Address. Even if the association is not bidirectional Atem gives you information about the association on the Address side. For Pojos extra information about the Address side can be provided by the @Association annotation:

class Person {

	@Association(targetAttribute="person", targetCardinality=Carginality.ZERO_ONE}
	private Address address;
}

Now we can access the association from the Address side:

EntityType<Address> addressType=entitTypeRepository.getEntityType(Address.class);
SingleAttribute<Person> attribute=addressType.getIncomingAssociation("person");

Without the extra information the incomingAssociation exists but its name is unknown.

To get the actual instance of Person that an instance of Address is associated with an instance of FindByAttributeService needs to be provided on the Person EntityType.

// let's find a person by its address
EntityType<Address> addressType=entitTypeRepository.getEntityType(Address.class);
// assuming that Person only has one association to Address
Attribute attribute=addressType.getIncomingAssociation("person");
// this will throw an exception if the FindByAttributeService is not implemented for Person
Person personLivingAtTheAddress= (Person) attribute.getValue(address);

Clone this wiki locally