);
*/
/*测试查询主题
Topic topic = app.query(1);
System.out.println(topic.getAuthor().getName());
*/
} catch (Exception e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
测试插入作者如图1所示,测试插入主题如图2所示,测试查询主题结果如下:
Hibernate: select topic0_.id as id1_, topic0_.name as name1_, topic0_.user_id as user_id1_, author1_.id as id0_, author1_.name as name0_ from topic topic0_ left outer join author author1_ on topic0_.user_id=author1_.id where topic0_.id=?
jack
生成的sql语句用到了join,查询结果为jack,与期望相符。
图一