Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] Virtual Metlhods | questions

Thanks tom. So this means less code  and it works :-)

So the OneToManyMapping looks like

private void oneToManyMapping(ClassDescriptor classDescriptor) {
		OneToManyMapping oneToManyMapping = new OneToManyMapping();
		oneToManyMapping.setDescriptor(classDescriptor);
		oneToManyMapping.setCascadeAll(true);
		oneToManyMapping.useTransparentList();
		
		VirtualAttributeAccessor virtualAttributeAccessor2 = new
VirtualAttributeAccessor();
		virtualAttributeAccessor2.setAttributeName("phoneNumbers");
		virtualAttributeAccessor2.setGetMethodName("get");
		virtualAttributeAccessor2.setSetMethodName("set");

	
virtualAttributeAccessor2.initializeAttributes(classDescriptor.getJavaClass());
		
		oneToManyMapping.setAttributeAccessor(virtualAttributeAccessor2);
		oneToManyMapping.setAttributeName("phoneNumbers");
		oneToManyMapping.setReferenceClass(PhoneNumber.class);
		Vector<String> sourceFieldNames = new Vector<String>();
		sourceFieldNames.add("PHONE_NUMBER_ID");
		oneToManyMapping.setSourceKeyFieldNames(sourceFieldNames);
		
		
		Vector<String> targetFieldNames = new Vector<String>();
		targetFieldNames.add("ID");
		oneToManyMapping.setTargetForeignKeyFieldNames(targetFieldNames);
		
		classDescriptor.getMappings().add(oneToManyMapping);
	}

Now I can remove getListValueHolder and setListValueHolder and
getPhoneNumber will look like

public List<PhoneNumber> getPhoneNumbers() {
		Object phoneNumbers = get("phoneNumbers");
		
		if (phoneNumbers != null) {
			return List.class.cast(get("phoneNumbers"));
		}
		
		set("phoneNumbers", new ArrayList<PhoneNumber>());
		
		return List.class.cast(get("phoneNumbers"));
		
	}



Hi Gaurav,

   In general, you should not have to manage the valueholders for your
xToMany 
relationships.  Instead of useBasicIndirection(), call 
useTransparentIndirection() for your xToManys and the LAZYness will be
managed 
under the covers.

-Tom
-- 
View this message in context: http://old.nabble.com/Virtual-Metlhods-%7C-questions-tp34172077p34184632.html
Sent from the EclipseLink - Users mailing list archive at Nabble.com.



Back to the top