-->
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.  [ 4 posts ] 
Author Message
 Post subject: not-null property references a null or transient value
PostPosted: Fri Jun 22, 2007 2:52 pm 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Hallo,

ich bekomme die Meldung dass ein Wert vor dem Persistiervorgang wohl noch auf null stehe, was aber absolut nicht stimmt, da ich debuggt habe.

Meine Klasse User hält ein Objekt vom Typ "UserProfile" welches als many-to-one gemapped ist. Nachdem ich es per "user.setProfile(theProfile);" gesetzt habe und es dann mittels "persist" in die Datenbank speichern möchte, bekommen ich folgende Exception:

Code:
org.hibernate.PropertyValueException: not-null property references a null or transient value: de.tfhberlin.eclipsophone.common.persistence.User.profile
   at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
   at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:290)
   at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
   at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:121)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:187)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:172)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:94)
   at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:70)
   at org.hibernate.impl.SessionImpl.fireSaveOrUpdate(SessionImpl.java:507)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:499)
   at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:495)
   at org.company.persistence.dao.WebClientUserDao.persist(WebClientUserDao.java:71)


So sieht das Mapping von User aus:

Code:
<hibernate-mapping>
   <class name="org.company.persistence.User" table="user">
      <id name="id" column="id" type="java.lang.Integer">
         <generator class="increment" />
      </id>
      
      <property name="name" column="name" type="java.lang.String" />
      
      <set name="subscriptions" inverse="true">
         <key>
            <column name="user_id"></column>
         </key>
         <one-to-many class="org.company.persistence.UserGroupSubscriptionstatus"/>
      </set>      
      
       <property name="status" type="org.company.persistence.HibernateUserStateEnum" not-null="true"/>

       <property name="activated" type="org.company.persistence.HibernateEntityActivatedEnum" not-null="true"/>

        <many-to-one name="profile" class="org.company.persistence.UserProfile" fetch="select">
            <column name="profile_id" not-null="true" />
        </many-to-one>      
   </class>
</hibernate-mapping>



Code:
      User user = new User();
      user.setActivated(ActivatedType.activated);
      user.setName(username);
      user.setStatus(Userstatus.loggedOut);
      UserProfile up = new UserProfile();
      up.setPassword(password);
      user.setProfile(up);
      return userDao.persist(user);


Wo liegt denn hier der Fehler?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 24, 2007 4:16 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Hallo,

Bitte entschuldige mein Deutsch. Ich spreche nicht oft :-).

Ich denke dass dein program nur brauche zu persist auch den UserProfile (up). Etwas als :
Code:
      User user = new User();
      user.setActivated(ActivatedType.activated);
      user.setName(username);
      user.setStatus(Userstatus.loggedOut);
      UserProfile up = new UserProfile();
      up.setPassword(password);
      user.setProfile(up);
      session.persist(up);
      return userDao.persist(user);

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 2:44 am 
Regular
Regular

Joined: Wed Nov 01, 2006 2:17 pm
Posts: 78
Danke! Genau da lag der Fehler! Vielen Dank.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 25, 2007 4:17 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Bitte.

(Baptiste, erste deutschen hilfe :-))

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


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

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.