Hibernate使用问题小结

  •  映射未找到异常

原因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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值