I have problem with constructor mapping. Here is the query:
@Query("select new com.logate.lts.core.web.dto.customer.CustomerRelationshipV360DTO(" +
"customerRelationship.customerRelationshipType, " +
"case when customerFrom.id = :customerId " +
"or customerRelationship.customerRelationshipType.isBidirectionalRelation = 1 then customerTo " +
"else customerFrom end) " +
"from CustomerRelationship customerRelationship " +
"left join customerRelationship.customerFrom customerFrom " +
"left join customerRelationship.customerTo customerTo " +
"where (customerFrom.id = :customerId or customerTo.id = :customerId)")
List<CustomerRelationshipV360DTO> getAllRelationshipsForCustomer(@Param("customerId") Long customerId);
Here is the entity class:
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "attribute_one_value")
@NotAudited
private String attributeOneValue;
@Column(name = "attribute_two_value")
@NotAudited
private String attributeTwoValue;
@Column(name = "note")
private String note;
@ManyToOne
@JoinColumn(name = "customer_relationship_type_id")
@Audited(targetAuditMode = RelationTargetAuditMode.NOT_AUDITED)
private CustomerRelationshipType customerRelationshipType;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
@JoinColumn(name = "customer_from_id")
private Customer customerFrom;
@ManyToOne(fetch = FetchType.LAZY)
@JsonIgnore
@JoinColumn(name = "customer_to_id")
private Customer customerTo;
(getters and setters)
Here is the DTO class:
private Long customerId;
private String customerName;
private String customerPrimaryIdentifier;
private CustomerRelationshipType relationshipType;
@SuppressWarnings("unused")
public CustomerRelationshipV360DTO() {
// default constructor...
}
/**
* Constructor mapping
*
* @param relationshipType given customer relationship type
* @param targetCustomer given target customer
*/
public CustomerRelationshipV360DTO(CustomerRelationshipType relationshipType, Customer targetCustomer)
{
this.customerId = targetCustomer.getId();
this.customerName = targetCustomer.getName();
this.customerPrimaryIdentifier = targetCustomer.getPrimaryIdentifier();
this.relationshipType = relationshipType;
}
(getters and setters)
and I’m getting the following errror:
org.hibernate.QueryException: could not instantiate class [com.logate.lts.core.web.dto.customer.CustomerRelationshipV360DTO] from tuple; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: could not instantiate class [com.logate.lts.core.web.dto.customer.CustomerRelationshipV360DTO] from tuple
Can anyone help me?
Thank you in advance.