81,095
社区成员
发帖
与我相关
我的任务
分享
package com.menglei.shili;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
@Entity
@Table(name="Msg")
public class Msg {
private int id;
private String count;
private Topic topic;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getCount() {
return count;
}
public void setCount(String count) {
this.count = count;
}
@ManyToOne
@JoinColumn(name="Tid")
public Topic getTopic() {
return topic;
}
public void setTopic(Topic topic) {
this.topic = topic;
}
}
这是测试类中代码: Query q=session.createQuery(" from Msg m where m.id= :MsgToSearch");
Msg m=new Msg();
m.setId(1);
q.setParameter("MsgToSearch", m.getId());
Msg mResult =(Msg)q.uniqueResult();
System.out.print(mResult.getCount());