HIBERNATE ONE-TO-ONE ERROR

WARN - JDBCExceptionReporter.logExceptions(71) | SQL Error: 1452, SQLState: 23000
ERROR - JDBCExceptionReporter.logExceptions(72) | Cannot add or update a child row: a foreign key constraint fails

(`test/qkzl_mz_zixun`, CONSTRAINT `FKA2119283BE699597` FOREIGN KEY (`id`) REFERENCES `qkzl_mz_gh` (`id`))

 解决方案:

一对一表时的关系,外表建主键时配置:

 /**
  * @hibernate.id column="id" type="long" unsaved-value="-1"
  *               generator-class="foreign"
  *               @hibernate.generator-param  name="property" value="guahao"
  * @return
  */

*.hbm.xml中
   <generator class="foreign">
                <param name="property">guahao</param>

你可能感兴趣的:(sql,xml,Hibernate)