JPA和Spring Data

1.添加jar包

2.改配置

3.底层dao脑袋上是@PersistContext

4.拦截RuntimeException 默认拦截

不拦截非RuntimeException



5.四个 roll‘BackFor=Exception.class   默认为运行时异常

四个  数据的隔离机制, rollbackfor  ,  readonly,propagetion


6.配置springdata

1.导入jar

2.配置xml

1.扫描的包

2.c3p0数据源

3.jpa  entityManagerFactory

4.事务管理(前四个是spring和jpa整合步骤)

5.springdata配置   加JPA xml中  勾上 ,repository不用勾,配置一个东西


7.ApplicationContext ac = new ClassPathXmlApplicationContext("配置文件名.xml");


8.extends Repository<Person,Integerl>


9.修改  @modifying  @Query   还得加事务,自己写sql


10.自定义的,PersonDao  接口   PersonRepositoryImpl  实现类 ,PersonRepository继承PersonDao,调用personRepository即可


11.Spring Data  entityManager


12.修改操作的话,三个注意

1.需要自己写update语句,@Query(value="面向对象的语句sql")

2.需要在方法上加@modifying

3.一定要有事务才可以运行


1.单向多对一 好用,默认积极加载,eaygl

2.单向一对多,默认懒加载  lazy 

3.级联删除,cascade={cascadetype. v}


你可能感兴趣的:(JPA和Spring Data)