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