-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Fehler bei session.delete()
PostPosted: Sat May 23, 2009 12:54 pm 
Newbie

Joined: Thu May 21, 2009 1:34 pm
Posts: 2
Code:
session.delete(video);

Wenn ich versuche diesen Code auszuführen bekomme ich folgende Fehlermeldung:
781 [main] WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 1048, SQLState: 23000
781 [main] ERROR org.hibernate.util.JDBCExceptionReporter - Column 'ownerId' cannot be null
781 [main] ERROR org.hibernate.event.def.AbstractFlushingEventListener - Could not synchronize database state with session

Ich bekomme diese Fehlermeldung weil Hibernate versucht die ownerId auf null zu setzen, das aber vom Datenmodell her nicht erlaubt ist. When ich in der MySQL Datenbank der ownerId erlaube null zu sein, funktioniert ist. Ich weiß nicht warum Hibernate versucht das ein Update auf das Video abzusetzen, obwohl ich es nur löschen will.
Code:
Hibernate: update video set ownerId=?, lenderId=?, germanTitle=?, originalTitle=?, genre=?, country=?, year=?, runningTime=?, certificate=?, director=?, producer=?, music=?, camera=?, editing=?, description=?, medium=?, lendingDate=?, audioTrack=?, cast=?, language=?, subtitle=? where videoId=?

Hibernate: update video set ownerId=?, lenderId=?, germanTitle=?, originalTitle=?, genre=?, country=?, year=?, runningTime=?, certificate=?, director=?, producer=?, music=?, camera=?, editing=?, description=?, medium=?, lendingDate=?, audioTrack=?, cast=?, language=?, subtitle=? where videoId=?

Hibernate: update video set ownerId=null where ownerId=? and videoId=?


Hier sind meine config files:
Video.hbm.xml:
Code:
  <hibernate-mapping>
   <class name="at.uvf.model.Video" table="video" >
      <id name="id" type="java.lang.Long" column="videoId">
         <generator class="increment" />
      </id>
      <property name="ownerId" type="java.lang.Long" column="ownerId" length="-1" not-null="true" />
      <property name="lenderId" type="java.lang.Long" column="lenderId" length="25" />
      <property name="germanTitle" type="java.lang.String" column="germanTitle" length="64" />
      <property name="originalTitle" type="java.lang.String" column="originalTitle" length="64" not-null="true" />
      <property name="genre" type="java.lang.String" column="genre" length="64" />
      <property name="country" type="java.lang.String" column="country" length="64" />
      <property name="year" type="java.lang.Integer" column="year" length="-1" />
      <property name="runningTime" type="java.lang.Integer" column="runningTime" length="-1" />
      <property name="certificate" type="java.lang.Integer" column="certificate" length="-1" />
      <property name="director" type="java.lang.String" column="director" length="64" />
      <property name="producer" type="java.lang.String" column="producer" length="64" />
      <property name="music" type="java.lang.String" column="music" length="64" />
      <property name="camera" type="java.lang.String" column="camera" length="64" />
      <property name="editing" type="java.lang.String" column="editing" length="64" />
      <property name="description" type="java.lang.String" column="description" length="5000" />
      <property name="medium" type="java.lang.String" column="medium" length="64" />
      <property name="lendingDate" type="java.util.Date" column="lendingDate" length="-1" />
      <property name="audioTrack" type="java.lang.String" column="audioTrack" length="64" />
      <property name="cast" type="java.lang.String" column="cast" length="200" />
      <property name="language" type="java.lang.String" column="language" length="64" />
      <property name="subtitle" type="java.lang.String" column="subtitle" length="64" />

      <many-to-one name="owner" column="ownerId" insert="false" update="false" />
      <many-to-one name="lender" column="lenderId" insert="false" update="false" />
   </class>
</hibernate-mapping>


User.hbm.xml:
Code:
  <hibernate-mapping>
   <class name="at.uvf.model.User" table="user" >
      <id name="id" type="java.lang.Long" column="userId">
         <generator class="increment" />
      </id>
      <property name="nickname" type="java.lang.String" column="nickname" length="25" not-null="true" />
      <property name="password" type="java.lang.String" column="password" length="25" not-null="true" />
      <property name="maxLending" type="java.lang.Integer" column="maxLending" length="-1" not-null="true" />


      <set name="myVideos" cascade="all">
         <key column="ownerId"/>
         <one-to-many class="at.uvf.model.Video" />
      </set>

      <set name="lentVideos" cascade="all">
         <key column="lenderId"/>
         <one-to-many class="at.uvf.model.Video" />
      </set>
           
      <set name="friends" table="friendship" cascade="all">
         <key column="userId1" />
         <many-to-many column="userId2" class="at.uvf.model.User" />
      </set>

      <set name="addedFriends" table="askedFriendship">
         <key column="askingUserId"/>
         <many-to-many column="askedUserId" class="at.uvf.model.User"/>
      </set>

      <set name="waitingFriends" table="askedFriendship">
         <key column="askedUserId"/>
         <many-to-many column="askingUserId" class="at.uvf.model.User"/>
      </set>

   </class>
</hibernate-mapping>



hibernate.cfg.xml
Code:
<hibernate-configuration>
   <session-factory>
      <property name="connection.url">jdbc:mysql://localhost:3306/uvf</property>
      <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
      <property name="connection.username">root</property>
      <property name="connection.password">123</property>     
      <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
      <!-- Mapping files -->
      <mapping resource="at/uvf/model/User.hbm.xml" />
      <mapping resource="at/uvf/model/Video.hbm.xml" />
   </session-factory>
</hibernate-configuration>


Ich hoffe, dass es möglich ist dieses Problem zu lösen, ohne SQL-Code verwenden zu müssen.
Danke im voraus.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.