Hi,
I am getting error while doing a findAll query on a table(Message - in my case) that has a foreign-key relationship with another table (Department). When I execute findall, it is mapping a String instead of Department object.
How I have to define the NamedQuery in this case?
Code:
@NamedQueries({
@NamedQuery(
name="findMessagesById",
query="select message " +
"FROM Message message " +
"where message.consumer.id = :messageId"
)
})
@SqlResultSetMappings({
@SqlResultSetMapping(name="findMessagesById",
entities={@EntityResult(entityClass=com.pcg.mbadmin.domain.Message.class)}
),
@SqlResultSetMapping(name="findMessageById",
entities={@EntityResult(entityClass=Message.class)}
)
})
//Member declaration
@ManyToOne (fetch=FetchType.EAGER)
@JoinColumn(name = "CONSUMER_ID", nullable = false, referencedColumnName="DEPARTMENT_ID")
private Department consumer;