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错误的更多相关文章

  1. idea中Hibernate错误:无法解析表

    idea中Hibernate错误:无法解析表 这种情况主要是在idea中使用hibernate自定义注解,idea无法检查数据源 this inspecton controls whether the ...

  2. Hibernate 错误处理

    1. 在处理映射 1 对 n 时,Customer类为 1, Order类为 n,对象关系映射文件中没有错误,<many to one> 也正确,表名通类名. 但是,在执行插入时,发生两个 ...

  3. Spring集成hibernate错误

    八月 25, 2016 7:55:31 下午 org.apache.tomcat.util.digester.SetPropertiesRule begin警告: [SetPropertiesRule ...

  4. hibernate 错误 could not determine type for

    今天配置实体类注解时,出现以下错误: org.hibernate.MappingException: Could not determine type for: com.oneToOne.IdCard ...

  5. Hibernate错误:javax/persistence/EntityListeners

    1. 原文地址:http://heavengate.blog.163.com/blog/static/20238105320127291018026/ 错误信息: hibernate:javax/pe ...

  6. Hibernate错误——No row with the given identifier exists

    错误 是用的是Hibernate自动建立的数据表,在进行数据库操作时,出现错误No row with the given identifier exists 解决 关系数据库一致性遭到了破坏,找到相关 ...

  7. hibernate错误提示

    2016-05-03 09:45:03,275 -- WARN  -- org.hibernate.internal.util.xml.DTDEntityResolver.resolveEntity( ...

  8. 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 ...

  9. Hibernate错误:Could not bind factory to JNDI

    使用hibernate时,将hibernate.cfg.xml中 <session-factory name="SessionFactory">的那么属性去掉即可.因为 ...

  10. Hibernate错误及解决办法

    1.Hibernate 报错:this project is not a myeclipse hibernate project . assuming hibernate 3 cap res:项目名上 ...

随机推荐

  1. springboot 集成elasticsearch5.4.3

    官网上对elasticsearch 的集成用的是spring-data,而且,暂时不支持5.x的版本, 要是想集成5.x的版本,我们只能在pom.xml文件中进行修改,如图: <project ...

  2. butterknife用法总结

  3. sql语句建表,并且自增加主键

    sql语句建表,并且自增加主键 use [test] CREATE TABLE [dbo].[Table_4] ( [userid] [int] IDENTITY(1,1) NOT NULL, CON ...

  4. iptables 介绍

    规则链 规则链的作用:对数据包进行过滤或处理 链的作用:容纳各种防火墙规则 链的分类依据:处理数据包的不同时机 默认包括5种规则链 INPUT:处理入站数据包 OUTPUT:处理出站数据包 FORWA ...

  5. poj_1042 贪心算法

    poj 1042 gone fishing 题目要求: 由有n个湖, 按照顺序排列,一个人从第一个湖向最后一个湖行进(方向只能从湖0到湖n-1),途中可以在湖中钓鱼.在每个湖中钓鱼时,开始的5分钟内可 ...

  6. String 类实现 以及>> <<流插入/流提取运算符重载

    简单版的String类,旨在说明>> <<重载 #include <iostream> //#include <cstring>//包含char*的字符 ...

  7. How to Use Postman to Manage and Execute Your APIs

    How to Use Postman to Manage and Execute Your APIs Postman is convenient for executing APIs because ...

  8. 在openLdap上添加memberOf属性

    我为openldap添加memberof属性的时候参考了这个文章:http://www.adimian.com/blog/2014/10/how-to-enable-memberof-using-op ...

  9. C# DataTbale详细操作

    1.创建DataTable对象 DataTable dt = new DataTable("Table_AX"); 2.为DataTable创建列 //方式一(我觉得这种好) dt ...

  10. State Server实现多机器多站点 Session 共享 全手记

    网络环境有2台windows 2008 (192.168.1.71,192.168.1.72) 需要部署成 WebFarm,提高容错性. 网站部署在2台机器上的2个站点,如何才能做到Session的共 ...