<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- 是否显示SQL语句 --> <property name="show_sql">true</property> <!-- SQL��数据库方言��SQLServer --> <property name="dialect">org.hibernate.dialect.SQLServerDialect</property> <!-- JDBC�Driver --> <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property> <!-- JDBC URL --> <property name="connection.url">jdbc:sqlserver://localhost:1433;databaseName=demo;</property> <!-- 用户名� --> <property name="connection.username">sa</property> <!-- 密码 --> <property name="connection.password">sonicluo3</property> <!--数据库连接池--> <property name="c3p0.min_size">5</property> <property name="c3p0.max_size">20</property> <property name="c3p0.timeout">1800</property> <property name="c3p0.max_statements">50</property> <!-- 配置每次提交SQL的数量 --> <property name=" hibernate.jdbc.batch_size">50</property> <!-- 关系映射 --> <mapping resource="com/sonic/User.hbm.xml"/> <mapping resource="com/sonic/Room.hbm.xml"/> </session-factory> </hibernate-configuration>
按照上面的配置hibernate和SQLServer2005连接配置,但是出现了下面的情况
org.springframework.dao.DataIntegrityViolationException: could not insert: [cn.blueram.oa.model.User]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [cn.blueram.oa.model.User]
提示user附近出现错误;
原因是我使用的user作为t_usersroles表的字段;
和数据库表冲突吧,改成其它就可以了