How to embed child classes based on abstract class Id

Hi @yrodiere ,
I have mapped an abstract class named profile in one of my entity class as below

@Getter
@Setter
@Indexed(index = “ind_source_copy”)
@Slf4j(topic = “SOURCE_COPY”)
@Entity(name = Source_Copy.TABLE_NAME)
public class Source_Copy {

public static final String TABLE_NAME = "tblm_source_copy";
public static final String ID_COLUMN = "datasource_id";


@Autowired
ProfileRepository profileRepository;

@Id
@Column(name = ID_COLUMN, nullable = false, length = 63)
@FullTextField(name = ID_COLUMN)
@DocumentId
private String id;

@Column(name = DOMAIN_COLUMN, length = 15)
@KeywordField(name = DOMAIN_COLUMN,normalizer = "lowercase")
@Enumerated(EnumType.STRING)
private DomainEnum domain;

@Column(name = SOURCE_TYPE_COLUMN, length = 15)
@KeywordField(name = SOURCE_TYPE_COLUMN,normalizer = "lowercase")
@Enumerated(EnumType.STRING)
private SourceTypeEnum sourceType;


@Column(name = STATUS_COLUMN, length = 15)
@Enumerated(EnumType.STRING)
@KeywordField(name = STATUS_COLUMN,normalizer = "lowercase")
private Status status;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "profile_id")
@IndexingDependency(reindexOnUpdate = ReindexOnUpdate.SHALLOW)
@IndexedEmbedded
public Profile profile;

public Profile getProfile() {
   
    return profile;
}

public void setProfile(Profile profile) {
    Example profileTypeExample;
    if(DataDomainEnum.EDUCATION.equals(dataDomain))
    {
        EducationProfile educationProfile = new EducationProfile();
        educationProfile.setProfileId(profile.getProfileId());
        profileTypeExample = Example.of(educationProfile);
        this.profile = (EducationProfile) profileRepository.findAll(profileTypeExample).get(0);
    }
    else{
        EmploymentProfile employmentProfile = new EmploymentProfile();
        employmentProfile.setProfileId(profile.getProfileId());
        profileTypeExample = Example.of(employmentProfile);
        this.profile = (EmploymentProfile) profileRepository.findAll(profileTypeExample).get(0);
    }
}

and my abstract class is as below , i have used joined inheritance strategy
@Getter
@Setter
@Slf4j(topic = “PROFILE”)
@ToString
@Entity(name = Profile.TABLE_NAME)
@Inheritance(strategy = InheritanceType.JOINED)
@TypeDefs({
@TypeDef(
typeClass = JsonBinaryType.class,
defaultForType = JsonNode.class
),
@TypeDef(name = “json”, typeClass = JsonStringType.class)
})
public abstract class Profile {

public static final String ID_COLUMN = "profile_id";
public static final String TABLE_NAME = "tblm_profile";
public static final String USAGE_PERIOD = "usage_period";
public static final String  LOGIN_INFO = "login_info";

@Id
@GeneratedValue(strategy=GenerationType.TABLE)
@Column(name = ID_COLUMN, nullable = false, length = 63)
@FullTextField(name = ID_COLUMN)
@DocumentId
protected String profileId;

@FullTextField
@Column
protected String name;

@JsonProperty(LOGIN_INFO)
@Column(name = LOGIN_INFO,columnDefinition = "jsonb")
protected JsonNode loginInfo;

@JsonProperty(USAGE_PERIOD)
@Type(type = "json")
@Column(name = USAGE_PERIOD,columnDefinition = "jsonb")
protected List<UsagePeriodInfo> usagePeriod;

@FullTextField
@Column
protected String website;

}
child classes are as below ,
@Getter
@Setter
@Slf4j(topic = “EDUCATION_PROFILE”)
@ToString
@Entity(name = EducationProfile.TABLE_NAME)
@Indexed(index = “ind_education_profile”)
public class EducationProfile extends Profile{

public static final String TABLE_NAME = "tblm_education_profile";



private static final String ID_COLUMN = "id";


@FullTextField(name = SCHOOL_ID_COLUMN)
@JsonProperty("school_id")
@Column(name ="school_id")
private String schoolId;

@JsonProperty("sis_type")
@Column(name ="sis_type")
private String sisType;

@JsonProperty("sis_url")
@FullTextField(name = SIS_URL_COLUMN, projectable = Projectable.YES,
        analyzer =  "standardProfileAnalyzer")
@Column(name ="sis_url")
private String sisURL;

@KeywordField(name = CAMPUS_CODE)
@JsonProperty(CAMPUS_CODE)
@Column(name =CAMPUS_CODE)
private String campusCode;

@KeywordField(name = REGISTRAR_EMAIL)
@JsonProperty(REGISTRAR_EMAIL)
@Column(name =REGISTRAR_EMAIL)
private String registrarEmail;

@KeywordField(name = REGISTRAR_PHONE)
@JsonProperty(REGISTRAR_PHONE)
@Column(name = REGISTRAR_PHONE)
private String registrarPhone;

@KeywordField(name = IPEDS_ID_COLUMN)
@JsonProperty(IPEDS_ID_COLUMN)
@Column(name = IPEDS_ID_COLUMN)
private String ipedsId;

@KeywordField(name = CEEB_ID_COLUMN)
@JsonProperty(CEEB_ID_COLUMN)
@Column(name = CEEB_ID_COLUMN)
private String ceebId;

@JsonProperty("op_id")
private String opId;

@GenericField(name = EARLIEST_GRADUATION_YEAR)
@JsonProperty("earliest_graduation_year")
@Column(name = EARLIEST_GRADUATION_YEAR)
private Integer earliestGraduationYear;


@KeywordField(name = SIC_CODE_COLUMN)
@JsonProperty("sic_code")
@Column(name = SIC_CODE_COLUMN)
private String sicCode;

@javax.persistence.Transient
@FullTextField(name="ALL")
@IndexingDependency(derivedFrom = {
        @ObjectPath(@PropertyValue(propertyName = "sicCode")),
        @ObjectPath(@PropertyValue(propertyName = "ceebId")),
        @ObjectPath(@PropertyValue(propertyName = "ipedsId")),
        @ObjectPath(@PropertyValue(propertyName = "schoolId")),
        @ObjectPath(@PropertyValue(propertyName = "sisURL")),
        @ObjectPath(@PropertyValue(propertyName = "name"))
})
public List<String> getAll() {
    return Arrays.asList(sicCode,ceebId,ipedsId
            ,schoolId,sisURL,name);
}

}
@Getter
@Setter
@Slf4j(topic = “EMPLOYMENT_PROFILE”)
@ToString
@Entity(name = EmploymentProfile.TABLE_NAME)
@Indexed(index = “ind_employment_profile”)
@TypeDefs(@TypeDef(name = “jsonb”, typeClass = JsonBinaryType.class))
public class EmploymentProfile extends Profile{

public static final String TABLE_NAME = "tblm_employment_profile";



@JsonProperty(SIS_URL_COLUMN)
@FullTextField(name = SIS_URL_COLUMN, projectable = Projectable.YES,
        analyzer =  "standardProfileAnalyzer")
@Column(name=SIS_URL_COLUMN)
private String sisURL;

@KeywordField(name = PHONE_NUMBER)
@JsonProperty(PHONE_NUMBER)
@Column(name = PHONE_NUMBER)
private String phoneNumber;


@KeywordField(name = SIC_CODE_COLUMN)
@JsonProperty(SIC_CODE_COLUMN)
@Column(name = SIC_CODE_COLUMN)
private String sicCode;

@FullTextField(name = EMPLOYMENT_TYPE_COLUMN)
@JsonProperty(EMPLOYMENT_TYPE_COLUMN)
@Type(type = "json")
@Column(name = EMPLOYMENT_TYPE_COLUMN, columnDefinition = "jsonb")
private Set<String> employmentType;

@FullTextField(name = PAYROLL_PROCESSOR_COLUMN)
@JsonProperty(PAYROLL_PROCESSOR_COLUMN)
@Column(name = PAYROLL_PROCESSOR_COLUMN)
private String payrollProcessor;

@FullTextField(name = EMPLOYEE_LOGIN_URL_COLUMN)
@JsonProperty(EMPLOYEE_LOGIN_URL_COLUMN)
@Column(name = EMPLOYEE_LOGIN_URL_COLUMN)
private String employeeLoginURL;

@javax.persistence.Transient
@FullTextField(name="ALL")
@IndexingDependency(derivedFrom = {
        @ObjectPath(@PropertyValue(propertyName = "sicCode")),
        @ObjectPath(@PropertyValue(propertyName = "employmentType")),
        @ObjectPath(@PropertyValue(propertyName = "payrollProcessor")),
        @ObjectPath(@PropertyValue(propertyName = "employeeLoginURL")),
        @ObjectPath(@PropertyValue(propertyName = "sisURL")),
        @ObjectPath(@PropertyValue(propertyName = "name"))
})
public List<String> getAll() {
    return Arrays.asList(sicCode,employmentType.toString(),payrollProcessor,employeeLoginURL
            ,sisURL,name);
}

}
so now the issue is elasticsearch picks up only abstract class fields and embed it in source class but , not fields of its child classes, i have to embed child class based on base class profile Id , so tried to add that code in getter and setters above , but it always embed abstract class fields only ,
Please guide me for the above scenario , I need a way through which child class fields gets embedded based on abstract class profileId

Hello,

I don’t know if it’s you or me, but I don’t understand at all.

Please provide an example of a document Hibernate Search generates, and an example of what you would like instead.

Also, please use formatting:

```
<your code>
```

On second reading, I think you want runtime polymorphism on @IndexedEmbedded? If so, then that’s not supported (yet).

See java - lucene / hibernate search - Cannot search by fields in subclass in collection - Stack Overflow ; there’s a suggested workaround, but I’m not sure how you would implement it in Search 6. Maybe @IndexingDependency for abstract Method will be relevant to you, too.