欢迎来到天天文库
浏览记录
ID:36841209
大小:273.50 KB
页数:46页
时间:2019-05-10
《J2EE应用持久化和Hibernate(三)》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、第六讲–数据库连接和Hibernate(三)Hibernate开发实例内容安排MyEclipse开发Hibernate过程三种映射关系实例MyEclipse开发Hibernate过程创建Web/JAVA工程增加Hibernate功能MyEclipse->AddHibernateCapabilities确定数据库连接细节需要实现创建DBDriverWindow->ShowView->Other->DBBrowser生成Hibernate.cfg.xmlHibernate反向工程生成映射文件和类文件Addr.hbm.xmlAbst
2、ractAddr.javaAddr.javaAddrDAO.java一对一关联Userinfo表结构createtableUSERINFO(USERIDVARCHAR2(20)notnull,USERNAMEVARCHAR2(20),AGEVARCHAR2(20),ADDRIDVARCHAR2(20),PRIMARYKEY(USERID),CONSTRAINTaddridFOREIGNKEY(ADDRID)REFERENCESaddr(ADDRID))Addr表结构createtableADDR(ADDRIDVARCHAR2(
3、20)notnull,LOCATIONVARCHAR2(20),POSTCODEVARCHAR2(20),PRIMARYKEY(`ADDRID`))AddrPOJOpublicclassAddrimplementsjava.io.Serializable{//FieldsprivateStringaddrid;privateStringlocation;privateStringpostcode;}Addr映射描述4、ddrid"type="java.lang.String">5、="20"/>UserinfoPOJOpublicclassUserinfoimplementsjava.io.Serializable{//FieldsprivateStringuserid;privateAddraddr;privateStringusername;privateStringage;}Userinfo映射文件描述6、a.lang.String">7、rty>关联查询Sessionsession=HibernateSessionFactory.getSession();Userinfou=(Userinfo)session.load(Userinfo.class,"1001");System.out.println(u.getUsername());System.out.println(u.g8、etAddr().getLocation());HibernateSessionFactory.closeSession();关联保存Userinfou=newUserinfo();u.setUserid("1002");u.setUsername("JONES");u.se
4、ddrid"type="java.lang.String">5、="20"/>UserinfoPOJOpublicclassUserinfoimplementsjava.io.Serializable{//FieldsprivateStringuserid;privateAddraddr;privateStringusername;privateStringage;}Userinfo映射文件描述6、a.lang.String">7、rty>关联查询Sessionsession=HibernateSessionFactory.getSession();Userinfou=(Userinfo)session.load(Userinfo.class,"1001");System.out.println(u.getUsername());System.out.println(u.g8、etAddr().getLocation());HibernateSessionFactory.closeSession();关联保存Userinfou=newUserinfo();u.setUserid("1002");u.setUsername("JONES");u.se
5、="20"/>UserinfoPOJOpublicclassUserinfoimplementsjava.io.Serializable{//FieldsprivateStringuserid;privateAddraddr;privateStringusername;privateStringage;}Userinfo映射文件描述6、a.lang.String">7、rty>关联查询Sessionsession=HibernateSessionFactory.getSession();Userinfou=(Userinfo)session.load(Userinfo.class,"1001");System.out.println(u.getUsername());System.out.println(u.g8、etAddr().getLocation());HibernateSessionFactory.closeSession();关联保存Userinfou=newUserinfo();u.setUserid("1002");u.setUsername("JONES");u.se
6、a.lang.String">7、rty>关联查询Sessionsession=HibernateSessionFactory.getSession();Userinfou=(Userinfo)session.load(Userinfo.class,"1001");System.out.println(u.getUsername());System.out.println(u.g8、etAddr().getLocation());HibernateSessionFactory.closeSession();关联保存Userinfou=newUserinfo();u.setUserid("1002");u.setUsername("JONES");u.se
7、rty>关联查询Sessionsession=HibernateSessionFactory.getSession();Userinfou=(Userinfo)session.load(Userinfo.class,"1001");System.out.println(u.getUsername());System.out.println(u.g
8、etAddr().getLocation());HibernateSessionFactory.closeSession();关联保存Userinfou=newUserinfo();u.setUserid("1002");u.setUsername("JONES");u.se
此文档下载收益归作者所有