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:项目名上 ...
随机推荐
- 分析JobInProgress中Map/Reduce任务分配
1.JobTracker能否决定给当前的TaskTracker节点分配一个Job的具体的哪一个任务? 2.什么是map本地任务? 3.nonRunningMapCache的作用是什么? 4.从Task ...
- C++ template —— 实例化和模板实参演绎(四)
本篇讲解实例化和模板实参演绎-------------------------------------------------------------------------------------- ...
- Android开发训练之第五章——Building Apps with Connectivity & the Cloud
Building Apps with Connectivity & the Cloud These classes teach you how to connect your app to t ...
- Delphi应用程序的调试(十)调试器选项
可在两个级别上设置调试选项:工程级和环境级.在前面的讲解中讲解了工程级调试选项,通过主菜单[Project | Options…]打开如下对话框: 可在Debugger Options对话框中设置全局 ...
- 【Python系列】Python3获取控制台输入
""" 接收控制台的输入 How old are you? 18 How tall are you ? 180 How much do you weigh? 50 So ...
- C#项目学习 心得笔记本
CacheDependency 缓存 //创建缓存依赖项 CacheDependency dep = new CacheDependency(fileName); //创建缓存 HttpContext ...
- 查看iOS沙盒(SanBox)文件
转载:http://www.2cto.com/kf/201211/169212.html 每一个iOS程序都一个自己的文件系统,这个文件系统叫应用程序沙盒(SanBox),它存放这代码以外的文件,其他 ...
- 题目1440:Goldbach's Conjecture(哥达巴赫猜想)
题目链接:http://ac.jobdu.com/problem.php?pid=1440 详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus 参考代码: ...
- host.conf 文件
/etc/host.conf文件的作用是设置名称解析时的先后顺序/etc/hosts文件是在使用host解析时,手动的添加的主机记录/etc/relov.conf文件中设置DNS服务器名称以及缺省的域 ...
- Dokcer制作nginx镜像,提交镜像至仓库
生成Dockerfile FROM docker.io/hagaico/centos-base-6.5:latest MAINTAINER yatho yatho@163.com ENV DEBIAN ...