How get java types class from entity property


I need get java types class from entity properties, e.g I heve entity

public class Correction extends BaseIntegerIdEntity {
	private static final long serialVersionUID = -725049967988389714L;

	@OneToOne(fetch = FetchType.LAZY, optional = false)
	@JoinColumn(name = "BEFORE_POSITION_ID")
	protected DocumentSpecification beforePosition;

Now I need get java class type from property beforePosition.price Precisely I’d like to have method into pass entity and property property return java type class for
this property. Particularly I’m interest in case when property is complex e.g beforePosition.price

Hi @andrzej.paluch72

This is easy to do with MetadataTools and MetaPropertyPath, which are used by GUI components.
Code example:

    Metadata metadata = AppBeans.get(Metadata.NAME);
    MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);

    MetaClass metaClass = metadata.getClassNN(Correction.class);
    MetaPropertyPath metaPropertyPath = metadataTools.resolveMetaPropertyPathNN(metaClass, "beforePosition.price");
    Class targetJavaClass = metaPropertyPath.getRangeJavaClass();