I'm trying to get all user votes for messages in custom question:
List<Vote> list = sessionFactory.getCurrentSession()
.createQuery("from Vote as v left join v.message as m " +
"where m.question=:question and v.user=:user and v.voteType=:voteType")
.setParameter("question", question)
.setParameter("user", user)
.setParameter("voteType", VoteType.MESSAGE)
.list();
System.out.println(list.get(0).getMessage().getNumber());
And got exception in the last string:
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to ru.kapahgaiii.qa.domain.Vote ru.kapahgaiii.qa.repository.ChatDAOImpl.getVotes(ChatDAOImpl.java:114)
What am I doing wrong?
Vote.java:
@Entity
@Table(name = "votes")
public class Vote {
@Id
@GeneratedValue
@Column(name = "vote_id")
private Integer voteId;
@ManyToOne
@JoinColumn(name = "uid")
private User user;
@Column(name = "vote_type", length = 8)
@Enumerated(EnumType.STRING)
private VoteType voteType;
@ManyToOne
@JoinColumn(name = "message_id")
private Message message;
listreally containsVoteobjects?