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:项目名上 ...
随机推荐
- osgearth cache
<map name="readymap.org" type="geocentric"> <options> <!--Specify ...
- Win7 如何访问XP系统里的网上邻居?
Win7 如何访问XP系统里的网上邻居? [ 标签:win7,xp系统 ] 现有两台电脑,一台XP,一台WIN7,共用一个无线路由器(两者都是经无线网络连接路由器).可以从XP里访问WIN7里的共享文 ...
- React Native(九)——实现仿微信朋友圈发表动态功能
好像很久都没写博客了,罪过罪过~ 许是因为刚接触App有点生疏不得窍门吧,这个月还没有更新过文章.小个把月下来,还是觉得应该边学边总结,这样才能像大神靠近(最近刚接触同业的大牛级人物,还是从中学到了很 ...
- PCL—低层次视觉—关键点检测(iss&Trajkovic)
关键点检测往往需要和特征提取联合在一起,关键点检测的一个重要性质就是旋转不变性,也就是说,物体旋转后还能够检测出对应的关键点.不过说实话我觉的这个要求对机器人视觉来说是比较鸡肋的.因为机器人采集到的三 ...
- css3整理--word-wrap/word-break/white-space
word-wrap语法: word-wrap : normal | break-word normal : 默认值,单词如果单词超长,会冲出边界(单个单词超长,在当前行显示) break-word : ...
- css3整理--border-radius
1.border-radius 标准: border-top-left-radius: x y // 左上角,x 圆角水平半径, y 圆角垂直半径 border-top-right-radius:x ...
- Android O 获取APK文件权限 Demo案例
1. 通过 aapt 工具查看 APK权限 C:\Users\zh>adb pull /system/priv-app/Settings . /system/priv-app/Settings/ ...
- ios-toolchain-based-on-clang-for-linux
https://github.com/tpoechtrager/cctools-port.git https://www.embtoolkit.org
- html中相关知识点的汇总
1. Input的size与maxlength属性的区别 maxlength="500",表示input输入框中最多够输入500个字符.W3C标准指出maxlength规定文本字段 ...
- linux下的一些操作命令
1.切换到root账号下: su root 输入密码: 2.修改root账号密码: sudo passwd root 输入密码: 3.cat用法: 查看文件内容 cat 文件名 创建文件 ...