Hibernate错误
1.Field 'id' doesn't have a default value
原来是我的数据设计的时候,把主键的类型定义为int的,原本想是用自增的方式来的,可是由于自己的粗心,写sql语句的时候没有加上auto_increment,
所以在数据存储的时候老是报Field 'id' doesn't have a default value,id根本就没有值啊!!
2.Could not synchronize database state with session
不能在两个sessionFactory中交叉操作
public class UserService {
public static void save(String uname, String pwd, String telNum, String realName,
String gender, String email){
SessionFactory sf = HibernateUtil.getSessionFactory(); //本身已有sf
Session session = sf.openSession();
Transaction tx = session.beginTransaction();
User u = new User(uname,pwd,telNum,realName,gender,email);
session.save(u);
tx.commit();
session.close();
}
}
然后在测试文件中又创建新的sf
public class UserTest {
private static SessionFactory sf;
@BeforeClass
public static void init(){
sf = new AnnotationConfiguration().configure().buildSessionFactory(); //新建sf
}
@AfterClass
public static void destory(){
sf.close();
}
@Test
public void saveUser(){
UserService.save("guan", "guan", "15999828993", "ling", "男", "1396636115@qq.com"); //报错
}
}
Hibernate错误的更多相关文章
- idea中Hibernate错误:无法解析表
idea中Hibernate错误:无法解析表 这种情况主要是在idea中使用hibernate自定义注解,idea无法检查数据源 this inspecton controls whether the ...
- Hibernate 错误处理
1. 在处理映射 1 对 n 时,Customer类为 1, Order类为 n,对象关系映射文件中没有错误,<many to one> 也正确,表名通类名. 但是,在执行插入时,发生两个 ...
- Spring集成hibernate错误
八月 25, 2016 7:55:31 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule ...
- hibernate 错误 could not determine type for
今天配置实体类注解时,出现以下错误: org.hibernate.MappingException: Could not determine type for: com.oneToOne.IdCard ...
- Hibernate错误:javax/persistence/EntityListeners
1. 原文地址:http://heavengate.blog.163.com/blog/static/20238105320127291018026/ 错误信息: hibernate:javax/pe ...
- Hibernate错误——No row with the given identifier exists
错误 是用的是Hibernate自动建立的数据表,在进行数据库操作时,出现错误No row with the given identifier exists 解决 关系数据库一致性遭到了破坏,找到相关 ...
- hibernate错误提示
2016-05-03 09:45:03,275 -- WARN -- org.hibernate.internal.util.xml.DTDEntityResolver.resolveEntity( ...
- Hibernate错误:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execute JDBC batch update
报错:Exception in thread "main" org.hibernate.exception.SQLGrammarException: Could not execu ...
- Hibernate错误:Could not bind factory to JNDI
使用hibernate时,将hibernate.cfg.xml中 <session-factory name="SessionFactory">的那么属性去掉即可.因为 ...
- Hibernate错误及解决办法
1.Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap res:项目名上 ...
随机推荐
- [Ubuntu] geoip-bin 程序包 - 查询 IP 归属地
简述:在Linux命令行下查询IP归属地. 对Ubuntu/Debian系统,使用APT命令进行安装: $ sudo apt-get install geoip-bin 该包由MaxMind提供,它同 ...
- 开源项目:MMTweenAnimation
本文转载至 http://adad184.com/2015/04/14/opensource-mmtweenanimation/ 前言 MMTweenAnimation其实酝酿了有一段时间了 起因是对 ...
- Myeclipse10使用git
用Myeclipse安装egit,使用官网最新地址或者下载最新的egit插件到本地安装均在team中看不到git,最后发现到http://download.eclipse.org/egit/updat ...
- Bootstrap - select2
1.调整select2下拉框的宽度 <style> .select2-container .select2-choice { height: 28px; line-height: 28px ...
- python基础---->python的使用(三)
今天是2017-05-03,这里记录一些python的基础使用方法.世上存在着不能流泪的悲哀,这种悲哀无法向人解释,即使解释人家也不会理解.它永远一成不变,如无风夜晚的雪花静静沉积在心底. Pytho ...
- PKI技术原理
转:http://3layer.blog.51cto.com/57448/20430 对称加密 symmetric cryptographic 非对称加密 asymmetric ...
- ALTERA FPGA Quartus 指定memory综合使用 M4K块
最近遇到个问题, 使用二位数组方式定义了一个RAM ,但是软件每次 都是使用逻辑单元综合 这块memory , 在ALTERA的网页上 找到了 方法,,在定义的 memory前面加一句画 (* ra ...
- jmeter中Implementation中几个选项的区别
在jmeter发送http请求时,Implementation下拉框中有几个选项,如下: 那到底有什么区别呢?发送http请求改用哪种方法呢.百度后查之,没答案.我们还是看官方文档吧.官方文档解释如下 ...
- Git - Pull Request工作流
Pull Requests是Bitbucket上方便开发者之间协作的功能.提供了一个用户友好的Web界面,在集成提交的变更到正式项目前可以对变更进行讨论. 开发者向团队成员通知功能开发已经完成,Pul ...
- thinkphp自动验证详解
自动验证时THINKPHP提供的一种比较好的验证方式,可以在使用create创建数据对象的时候自动进行数据验证. 数据进行自动验证的方式有两种: 1.静态方式:在模型类里面通过$_validate属性 ...