SSH框架中HIbernate能查询删除更新,不能插入,这是因为什么?? 
我表字段只有两个,而且插入前控制台输出时,对象的值都能输出,不存在插入值为空,报的错为: 
could not insert: [ssh.entity.Users]; nested exception is org.hibernate.exception.ConstraintViolationException: could not insert: [ssh.entity.Users]<hibernate-mapping>
    <class name="ssh.entity.Users" table="Users" schema="dbo" catalog="epet">
        <id name="userid" type="java.lang.String">
            <column name="userid" length="50" />
            <generator class="native"></generator>
        </id>
        <property name="password" type="java.lang.String">
            <column name="password" length="50" not-null="true" />
        </property>
    </class>
</hibernate-mapping>

解决方案 »

  1.   

    ConstraintViolationException
    约束冲突,我怀疑是因为你数据库底层设置的主键策略跟你用的主键策略冲突造成的。
    检查一下你的数据库设置。
      

  2.   

    1.你数据库是什么类型的 如果是oracle native 默认的类型就是sequence。那你就要在你的数据库创建sequence 。如果是mysql 默认的类型是auto increment. 主键就要选择 auto increment 选项。但是如果是1的话  报错应该不是你说的那样。2.从你的配置文件看  你的user 没有和其他表有任何关联关系。如果存在关联关系 那要考虑关联的属性。3.检查对象是否被锁住了。
      

  3.   

    我用的是SQLServer2005,只有一张表,没有和其他表有任何关联,想问下如何检查对象是否被锁定了?
    谢谢,本人是新手!
      

  4.   

    应该是主键或外键错误,建议把生成的sql拿到数据库中去执行看看
      

  5.   

    问题解决了,原来是我生成对象的时候ID Generator选的是native,native只能对表里面自动生成的主键字段有用,对一般的自然主键没有用,必须改成assigned,多谢上面的那位,你不说把sql显示出来,我还没发现问题哦