Hello!
I have Data Type Unknown exception when trying to query elements of the collection:
query is
List news = session.find(" from NewsDocument doc where ? in elements(doc.players)", player.getId(), Hibernate.LONG);
class is:
public class NewsDocument {
private Long id;
private String header;
private Set players;
/**
* @return
* @hibernate.set
* lazy = "true"
* inverse = "false"
* table = "NEWSDOCUMENTS_PLAYERS"
* @hibernate.collection-key
* column = "NEWSDOCUMENTS"
* @hibernate.collection-many-to-many
* class = "Player"
* column = "PLAYERS"
*/
public Set getPlayers() {
return players;
}
}
When I tried to query database that way, I got correct SQL Query:
select newsdocume0_.NEWSDOCUMENTID as NEWSDOCU1_,
newsdocume0_.BODY as BODY,
newsdocume0_.NEWSDATE as NEWSDATE,
newsdocume0_.HEADER as HEADER,
newsdocume0_.ISINJURY as ISINJURY,
newsdocume0_.ISTRANSACTION as ISTRANSA6_,
newsdocume0_.STATE as STATE
from NEWSDOCUMENTS newsdocume0_
where (? in
(select players1_.PLAYERS
from NEWSDOCUMENTS_PLAYERS
players1_ where newsdocume0_.NEWSDOCUMENTID=players1_.NEWSDOCUMENTS))
and, as mentioned above Data Type Unknown Exception.
Query " from NewsDocument doc where 1000 in elements(doc.players)"
works fine without any exceptions. Right now I got some workaround changing my query to
"select doc from NewsDocument doc join doc.players as player where player.id = ? ", but that result in inefficient query - we got an extra join:
select
newsdocume0_.NEWSDOCUMENTID as NEWSDOCU1_,
newsdocume0_.BODY as BODY,
newsdocume0_.NEWSDATE as NEWSDATE,
newsdocume0_.HEADER as HEADER,
newsdocume0_.ISINJURY as ISINJURY,
newsdocume0_.ISTRANSACTION as ISTRANSA6_,
newsdocume0_.STATE as STATE
from NEWSDOCUMENTS newsdocume0_
inner join NEWSDOCUMENTS_PLAYERS players1_
on newsdocume0_.NEWSDOCUMENTID=players1_.NEWSDOCUMENTS
inner join PLAYERS player2_ on players1_.PLAYERS=player2_.PLAYERID
where (player2_.PLAYERID=? )
|