使用Spring集成JPA.docVIP

  • 3
  • 0
  • 约7.37千字
  • 约 10页
  • 2018-03-09 发布于河南
  • 举报
使用Spring集成JPA

 HYPERLINK /spring/jpa_integration.html 使用Spring集成JPA 这里JPA的实现采用 HYPERLINK /hibernate/ \t _blank Hibernate,需要使用到下面的jar文件 Hiberante核心包(8个文件) hibernate-distribution-3.3.1.GA hibernate3.jar lib\bytecode\cglib\hibernate-cglib-repack-2.1_3.jar lib\required\*.jar Hiberante注解包(3个文件):hibernate-annotations-3.4.0.GA hibernate-annotations.jar lib\ejb3-persistence.jar、hibernate-commons-annotations.jar Hibernate针对JPA的实现包(3个文件):hibernate-entitymanager-3.4.0.GA hibernate-entitymanager.jar lib\test\log4j.jar、slf4j-log4j12.jar 遵循逐步集成的方式,首先集成 HYPERLINK /jpa/ \t _blank JPA跟 HYPERLINK /spring/ \t _blank Spring,当这两者集成成功后,我们再集成Struts persistence.xml ?xml version=1.0? persistence xmlns=/xml/ns/persistence xmlns:xsi=/2001/XMLSchema-instance xsi:schemaLocation=/xml/ns/persistence /xml/ns/persistence/persistence_1_0.xsd version=1.0 persistence-unit name=itcast transaction-type=RESOURCE_LOCAL properties property name=hibernate.dialect value=org.hibernate.dialect.MySQL5Dialect/ property name=hibernate.connection.driver_class value=org.gjt.mm.mysql.Driver/ property name=hibernate.connection.username value=root/ property name=hibernate.connection.password value=456/ property name=hibernate.connection.url value=jdbc:mysql://localhost:3306/springjdbc?useUnicode=trueamp;characterEncoding=UTF-8/ property name=hibernate.max_fetch_depth value=3/ property name=hibernate.hbm2ddl.auto value=update/ /properties /persistence-unit /persistence 接下来定义实体bean Person.java package cn.itcast.bean; import java.io.Serializable; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.Id; @Entity public class Person implements Serializable {// 推荐大家实现,当然不实现也可以 private Integer id; private String name; public Person() { } public Person(String name) { = name; } @Id @GeneratedValue

文档评论(0)

1亿VIP精品文档

相关文档