我試圖讓所有用戶投票爲自定義問題的消息:java.lang.Object中不能被轉換
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());
而最後的字符串中有例外:
的java.lang .ClassCastException:[Ljava.lang.Object;不能轉換爲 ru.kapahgaiii.qa.domain.Vote ru.kapahgaiii.qa.repository.ChatDAOImpl.getVotes(ChatDAOImpl.java:114)
我在做什麼錯?
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;
如果'list'確實包含'Vote'對象,你可以用調試器檢查一下嗎? –