I've got a value object for which i want to map my native query resultset.
I'm using @SQLResultSetMapping
to map object fields but when value of any column is null
, exception is throw:
Exception [EclipseLink-6177] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.QueryException
Exception Description: The column result [custom_properties] was not found in the results of the query.
My Entity Class and Mapping
@Entity
@Multitenant(MultitenantType.TABLE_PER_TENANT)
@Table(name = "account_master")
@SqlResultSetMapping(name = "DTO_MAPPING", classes = @ConstructorResult(
targetClass = AccountDTO.class,
columns = {@ColumnResult(name = "id"),
@ColumnResult(name = "name"),
@ColumnResult(name = "custom_properties")
})
)
public class Account implements Serializable {
// fields, setters and getters
}
Value Object:
public class AccountDTO {
public AssetDTO(){
}
public AssetDTO(int id, String name, String customProperties) {
this.id = id;
this.name = name;
this.customProperties = customProperties;
}
}
And the execution statement
List<AccountDTO> accList = entityManager.createNativeQuery("SELECT id, name, custom_properties FROM account_master WHERE acc_hierarchy <@ 2.3", "DTO_MAPPING").getResultList()
If custom_properties (which is nullable) is replaced by a static value in query, mapping works perfectly fine. Is there something wrong with the implementation? As mapping null value seems like a common scenario.
This was submitted as a bug in EclipseLink: https://bugs.eclipse.org/bugs/show_bug.cgi?id=484276
As a workaround, you can specify the type in the
annotation.
So you should change your code to: