这两天在试用hibernate,整合入springboot是没问题了,但是具体使用就有问题,大部分应该都是下面两个问题
1、required a bean of type 'org.hibernate.SessionFactory' that could not be found.
2、InvalidDataAccessApiUsageException 和 Write operations are not allowed in read-only mode
看例子代码比较容易,百度上面说的都很零散,这里我暂时使用的是HibernateDaoSupport里面自带的方法。
代码规范如上,Dao为数据操纵,Service为中间服务关联Dao和controller,controller为前端与Service的连接,主类为LanSpringTestApplication 。从上往下解释,注意红字部分为主要解决上面问题的关键。
1、LanSpringTestApplication
@EnableJpaRepositories("com.example.lan.dao") // JPA扫描该包路径下的Repositorie
@EntityScan("com.example.lan.entity") //