资源描述:
《hibernate_annotation》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、叮嘣HibernateAnnotation叮嘣使用hibernateAnnotation来映射实体准备工作下载hibernate-distribution-3.3.2.GAhibernate-annotations-3.4.0.GAslf4j导入相关依赖包HibernateHOME:hibernate3.jarlibbytecode(二进制)liboptional(可选的)librequired(必须的)导入required下的所有jar包antlr-2.7.6.jarcommon
2、s-collections-3.1.jardom4j-1.6.1.jarhibernate3.jarjavassist-3.9.0.GA.jarjta-1.1.jarslf4j-api-1.5.10.jarslf4j-log4j12-1.5.10.jarlog4j-1.2.14.jarmysql.jar---Annotation包ejb3-persistence.jarhibernate-annotations.jarhibernate-commons-annotations.jar叮嘣简单的例
3、子,通过annotation注解来映射实体PO1、建立(JavaProject)项目:hibernate_0100_annotation_HelloWorld_default2、在项目根下建立lib目录a)导入相关依赖jar包antlr-2.7.6.jarcommons-collections-3.1.jardom4j-1.6.1.jarejb3-persistence.jarhibernate-annotations.jarhibernate-commons-annotations.jarhi
4、bernate3.jarjavassist-3.9.0.GA.jarjta-1.1.jarlog4j-1.2.14.jarmysql.jarslf4j-api-1.5.10.jarslf4j-log4j12-1.5.10.jar3、建立PO持久化类cn.serup.model.Teacher内容如下packagecn.serup.model;importjavax.persistence.Entity;importjavax.persistence.Id;//@Entity表示该是实体类@Ent
5、itypublicclassTeacher{privateintid;privateStringusername;privateStringpassword;//ID为主键,主键手动分配@IdpublicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;叮嘣}publicStringgetUsername(){returnusername;}publicvoidsetUsername(Stringusername){this.usern
6、ame=username;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}}3、在src目录中建立hibernate.cfg.xml(hibernate配置文件)文件,内容如下
7、/EN""http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">jdbc:mysql://localhost/hibernateroot8、e="connection.password">sabercom.mysql.jdbc.Driverorg.hibernate.dialect.MySQLDialecttrue