-
映射未找到异常
原因hibernate.cfg.xml中引用的实体映射文件路径不正确
org.hibernate.boot.MappingNotFoundException: Mapping (RESOURCE) not found : com/pojo/User.hbm.xml
-
主键不唯一
在事务的最后执行SQL时,session缓存里面有多个主键一样的对象。
org.hibernate.NonUniqueObjectException: A different object with the same identifier value was already associated with the session
-
映射异常
不确定表字段的类型
org.hibernate.MappingException: Could not determine type for: String, at table: TB_USER
-
getter方法命名不符合JavaBean规范
getter,setter方法需要以get加首字母大写的属性名命名
org.hibernate.PropertyNotFoundException: Could not locate getter method for property [hibernate_in_2tb.bean.Customer#orders]
-
事务没有成功开启
原因:Hibernate配置方言不支持事务;回滚前先进行提交。
Exception in thread "main" java.lang.IllegalStateException: Transaction not successfully started
-
表名命名问题
hibernate实体映射文件中表名添加前缀,eg:TB_USER
WARN: GenerationTarget encountered exception accepting command : Error executing DDL "create table ORDER (ORDER_ID integer not null auto_increment, MONEY double precision, ADDRESS varchar(255), C integer, CUS_ID integer, primary key (ORDER_ID)) engine=InnoDB" via JDBC Statement
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "create table ORDER (ORDER_ID integer not null auto_increment, MONEY double precision, ADDRESS varchar(255), C integer, CUS_ID integer, primary key (ORDER_ID)) engine=InnoDB" via JDBC Statement