1

我正在尝试使用休眠进行一对一映射以将一些信息插入数据库,但每次尝试时都会出现此错误。

Caused by: org.hibernate.StaleStateException: Batch update returned unexpected row count from update [0]; actual row count: 0; expected: 1
at org.hibernate.jdbc.Expectations$BasicExpectation.checkBatched(Expectations.java:85)
at org.hibernate.jdbc.Expectations$BasicExpectation.verifyOutcome(Expectations.java:70)
at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:90)
at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:185)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1217)
at org.springframework.orm.hibernate3.SpringSessionSynchronization.beforeCommit(SpringSessionSynchronization.java:145)
... 12 more

这是我的 client.hbm.xml 文件。

<hibernate-mapping>
<class name="register.Client" table="client" lazy="false">
    <id name="clientId" type="string" column="CLIENT_ID"
        length="255">
        <generator class="increment"></generator>
    </id>
    <property name="address" type="string" column="ADDRESS"
        length="255" />
    <property name="email" type="string" column="EMAIL"
        length="255" />
    <property name="username" type="string" column="USERNAME"
        unique="true">
    </property>


    <!-- Associations -->
    <!-- bi-directional one-to-one association to Login -->
    <one-to-one name="login" class="login.UsrPwd" lazy="false"
         outer-join="auto" />
</hibernate-mapping>

这是我的 login.hbm.xml 文件

<hibernate-mapping>

<class name="login.UsrPwd" table="login">

    <id name="username" type="string" column="USER_NAME">   </id>   
    <property name="password" column="PASSWORD" type="string"/>
    <property name="type" column="TYPE_ID" type="int"></property>
    <one-to-one name="consultantInfo" class="register.ConsultantInfo"
        cascade="all" />

 <!--        bi-directional one-to-one association to Client -->
    <one-to-one name="client" class="register.Client"  cascade="all"/>
     </class>
 </hibernate-mapping>

当我运行我的函数将信息添加到数据库时,这是我得到的 SQL。

 Hibernate: insert into login (PASSWORD, TYPE_ID, USER_NAME) values (?, ?, ?)
 Hibernate: update client set ADDRESS=?, EMAIL=?, USERNAME=? where CLIENT_ID=?

我不认为第二个应该是更新的,因为该行还不存在,这就是它抛出我得到的异常的原因。我不知道它为什么这样做,任何帮助将不胜感激。

如果您需要更多信息,请告诉我,我可以提供

4

0 回答 0