hibernate 异常
2024-08-28 02:58:15
1.异常:org.hibernate.AnnotationException: No identifier specified for entity异常。
entity类是必须要主键的,否则就会报出这个异常。
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name = "id", nullable = false)
private Integer id;
2.异常:exception just for purpose of providing stack trace
count(*) 返回的结果为Long类型,而非Integer
3.异常 org.hibernate.UnknownEntityTypeException
在使用spring的orm时,entity类没在hibernate sessionFactory的扫描中,导致。@entity要使用javax的entity而不是hibernate的。
<bean id="sessionFactory"
class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="packagesToScan">
<list>
<!-- 可以加多个包 -->
<value>com.test.common.entity</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl.auto}</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
<prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate5.SpringSessionContext</prop>
<prop key="hibernate.format_sql">true</prop>
</props>
</property>
</bean>
4. org.hibernate.HibernateException: identifier of an instance of com.*.*DO was altered from 27 to null
出现这样的异常是从get中获取do对象,在进行更新前,将主键id给置为null导致。注意 BeanUtils.copyProperties,会将导入对象的null也给导入过来。
5. org.hibernate.HibernateException:Multiple references to database, sequence [**] were encountered attempting toset conflict values for initial value
出现的原因是在entity中有两个重复的实体类对应了sequence,多见于实体类重命名后mvn没有重新clean导致。 mvn clean package
最新文章
- Atitit onvif协议获取rtsp地址播放java语言 attilx总结
- zookeeper3.3.6 伪分布式安装
- LUA之string的使用
- mysql笔记02 创建高性能的索引
- CSS实现图片快速等比例缩放,效果佳
- SQL中N $ # @的作用
- VMware10.0.4下 CentOS 6.5 cmake安装 MySQL 5.5.32
- excel多个文件合并
- jQuery Validate验证框架使用
- qtcreator增加doxygen注释
- 吐槽CSDN编辑
- File和byte[]转换
- java解析上传的excel
- Idea中执行TestNg报错
- TCP/IP滑动窗口
- scala中Either的一种使用场景
- uni-app开发小程序准备阶段
- A1104. Sum of Number Segments
- Hadoop+HBase+Spark+Hive环境搭建
- 疑犯追踪第一季/全集Person Of Interest迅雷下载