Reputation: 2187
I'm building queries in HQL with join, and i've stack over one thing:
my query looks like:
From HistoryPerPhraseEntity as history left join history.linkAddressByLinkId where history.serviceId = :serviceId
and the query was fine, but when i was trying to throw response into my DataBase object and try to get values like this:
historyPhrase.get(0).getPhraseId()
i've got:
[Ljava.lang.Object; cannot be cast to com.rasp.lta.domain.HistoryPerPhraseEntity
but after change into this:
Select history From HistoryPerPhraseEntity as history left join history.linkAddressByLinkId where history.serviceId = :serviceId
everything is ok.
Could anybody answer why i need "Select from" in this query?
Thanks
Upvotes: 1
Views: 79
Reputation: 42114
Because without explicit SELECT Hibernate cannot figure out that only instances HistoryPerPhraseEntity should be returned. It returns also joined entities.
That's why it returns List of Object arrays. First index of array contains HistoryPerPhraseEntity and type of object in second index is same as type of element in linkAddressByLinkId collection.
If you for some reason want to access only HistoryPerPhraseEntity's returned by first query, that can be done by casting each element of returned list to Object[]
and casting Object[0]
to HistoryPerPhraseEntity
Better to use SELECT though.
Upvotes: 2