分享一个多多双向外键关联查询语句,想知道更多加我qq717310359。 String hql="select stu.email,tea.tname from st join stu on (st.sid = stu.sid )join tea on (st.tid = tea.tid)";
SQLQuery sqlQuery = session.createSQLQuery(hql);
List<Object[]> list = sqlQuery.list();
for (Object[] obj:list) {
System.out.println
SQLQuery sqlQuery = session.createSQLQuery(hql);
List<Object[]> list = sqlQuery.list();
for (Object[] obj:list) {
System.out.println
2016-04-20
其实我是想知道hibernate到底干嘛的。。不过这个都是在说注释哦。。。然后觉得链接数据库那里好难。。。。
2016-04-16
1,一对一
Student的属性sid 和Card的属性cid
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="sid",unique=true)
private Card card;
@OneToOne(mappedBy="cid")
private Student stu;//学生是主控方,身份证是被控方
Student的属性sid 和Card的属性cid
@OneToOne(cascade=CascadeType.ALL)
@JoinColumn(name="sid",unique=true)
private Card card;
@OneToOne(mappedBy="cid")
private Student stu;//学生是主控方,身份证是被控方
2016-04-07
2,多对一,设置EAGER,表示积极加载
Student的属性sid 和ClassRoom的属性cid
@ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinColumn(name="cid",referencedColumnName="CID")
private ClassRoom classRoom;
Student的属性sid 和ClassRoom的属性cid
@ManyToOne(cascade={CascadeType.ALL},fetch=FetchType.EAGER)
@JoinColumn(name="cid",referencedColumnName="CID")
private ClassRoom classRoom;
2016-04-07
3,一对多,设置LAZY,懒加载
Student的属性sid 和ClassRoom的属性cid
@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY)
@JoinColumn(name="cid")
private Set<Student> stus;
Student的属性sid 和ClassRoom的属性cid
@OneToMany(cascade={CascadeType.ALL},fetch=FetchType.LAZY)
@JoinColumn(name="cid")
private Set<Student> stus;
2016-04-07
4,多对多
Student的属性sid 和Teacher的属性tid
@ManyToMany
@JoinTable(
name="teacher_student",
joinColumns={@JoinColumn(name="sid")},
inverseJoinColumns={@JoinColumn(name="tid")})
private Set<Teacher> teacher;
@ManyToMany(mappedBy="teacher")
private Set<Student> stus;//学生是主控方。教师是被控方
Student的属性sid 和Teacher的属性tid
@ManyToMany
@JoinTable(
name="teacher_student",
joinColumns={@JoinColumn(name="sid")},
inverseJoinColumns={@JoinColumn(name="tid")})
private Set<Teacher> teacher;
@ManyToMany(mappedBy="teacher")
private Set<Student> stus;//学生是主控方。教师是被控方
2016-04-07