-->
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: Attempted to assign id from null one-to-one property
PostPosted: Thu Feb 19, 2009 8:23 am 
Newbie

Joined: Thu Feb 19, 2009 8:06 am
Posts: 5
Hi all,

I'm quite new to spring & hibernate and I get this error I've already said in the title of this post when trying to persist an object. Here are the mappings of the objects. Thank you all. If you need something else, just ask for it and I will post. I think is enough with the mapping files but I have no idea.

Hibernate version: 3.0

Mapping documents:

SdmValoraci
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "xxxx://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="xx.xxxxx.xxxxxx.model.SdmValoraci" table="SDM_VALORACI">
   <id
        name="pkValoraci"
        type="long"
        column="PK_VALORACI"
        length="22"
    >
      <generator class="sequence">
         <param name="sequence">SEC_SDM_VALORACI</param>
      </generator>
      
   </id>
   <property
        name="vacerrado"
        type="long"
        column="VACERRADO"
        not-null="true"
        length="22"
    />
   <property
        name="vafechcrea"
        type="date"
        column="VAFECHCREA"
        not-null="true"
        length="7"
    />
   <property
        name="vafechreal"
        type="date"
        column="VAFECHREAL"
        length="7"
    />
   <property
        name="vagrado"
        type="string"
        column="VAGRADO"
        length="1"
    />
   <property
        name="vanivel"
        type="string"
        column="VANIVEL"
        length="1"
    />
   <property
        name="vatipovalo"
        type="string"
        column="VATIPOVALO"
        length="3"
    />

   <!-- Associations -->
   <!-- bi-directional one-to-one association to SdmEve -->
   <one-to-one
        name="sdmEve"
        class="xx.xxxxx.xxxxxx.model.SdmEve"
        lazy="proxy"
        outer-join="auto"
        cascade="all"
    />   
   
    <!-- bi-directional one-to-one association to SdmBvd -->
   <one-to-one
        name="sdmBvd"
        class="xx.xxxxx.xxxxxx.model.SdmBvd"
        lazy="proxy"
        outer-join="auto"
       
    />     
   
   
   <!-- bi-directional one-to-one association to SdmInfoento -->
   <one-to-one
        name="sdmInfoento"
        class="xx.xxxxx.xxxxxx.model.SdmInfoento"
        lazy="proxy"
        outer-join="auto"
    />
   <!-- uni-directional many-to-one association to SdmDocugene -->
   <many-to-one
        name="sdmDocugene"
        class="xx.xxxxx.xxxxxx.model.SdmDocugene"
        lazy="proxy"
    >
      <column name="PK_DOCU" length="22"/>
   </many-to-one>
   <!-- uni-directional many-to-one association to SdxUsuario -->
   <many-to-one
        name="sdxUsuario"
        class="xx.xxxxx.xxxxxx.model.SdxUsuario"
        lazy="proxy"
    >
      <column name="PK_PERSONA" not-null="true" length="22"/>
   </many-to-one>
   <!-- bi-directional many-to-one association to SdmAsigsoli -->
   <many-to-one
        name="sdmAsigsoli"
        class="xx.xxxxx.xxxxxx.model.SdmAsigsoli"
        lazy="proxy"
    >
      <column name="PK_ASIGSOLI" not-null="true" length="22"/>
   </many-to-one>

</class>
</hibernate-mapping>



SdmEve
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "xxxx://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
<class name="xx.xxxxx.xxxxxx.model.SdmEve" table="SDM_EVE">
   <id
        name="pkValoraci"
        type="long"
        column="PK_VALORACI"
        length="22"
    >
      <generator class="foreign">
           <param name="property">sdmValoraci</param>
        </generator>
   </id>
   <property
        name="evmessol"
        type="long"
        column="EVMESSOL"
        not-null="true"
        length="22"
    />
   <property
        name="evpesonaci"
        type="long"
        column="EVPESONACI"
        length="22"
    />
   <property
        name="evpuntadap"
        type="long"
        column="EVPUNTADAP"
        length="22"
    />
   <property
        name="evpuntdesa"
        type="long"
        column="EVPUNTDESA"
        length="22"
    />
   <property
        name="evpuntfuvi"
        type="long"
        column="EVPUNTFUVI"
        length="22"
    />
   <property
        name="evpuntmotr"
        type="long"
        column="EVPUNTMOTR"
        length="22"
    />
   <property
        name="evpuntmovi"
        type="long"
        column="EVPUNTMOVI"
        length="22"
    />
   <property
        name="evpuntsalu"
        type="long"
        column="EVPUNTSALU"
        length="22"
    />

   <!-- Associations -->
   <!-- bi-directional one-to-one association to SdmValoraci -->
   <one-to-one
        name="sdmValoraci"
        class="xx.xxxxx.xxxxxx.model.SdmValoraci"
        lazy="proxy"
        outer-join="auto"
    />

</class>
</hibernate-mapping>



Full stack trace of any exception that occurs:
org.springframework.orm.hibernate3.HibernateSystemException: attempted to assign id from null one-to-one property: sdmValoraci; nested exception is org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: sdmValoraci

Caused by: org.hibernate.id.IdentifierGenerationException: attempted to assign id from null one-to-one property: sdmValoraci


Name and version of the database you are using:
Oracle 10g or so

The generated SQL (show_sql=true):


Debug level Hibernate log excerpt:
13:13:47,366 DEBUG org.hibernate.event.def.AbstractSaveEventListener,main:112 - generated identifier: 23, using strategy: org.hibernate.id.SequenceGenerator
13:13:47,366 DEBUG org.hibernate.event.def.AbstractSaveEventListener,main:153 - saving [xx.xxxxx.xxxxxx.model.SdmValoraci#23]
13:13:47,428 DEBUG org.hibernate.engine.Cascade,main:115 - processing cascade ACTION_SAVE_UPDATE for: xx.xxxxx.xxxxxx.model.SdmValoraci
13:13:47,428 DEBUG org.hibernate.engine.Cascade,main:150 - done processing cascade ACTION_SAVE_UPDATE for: xx.xxxxx.xxxxxx.model.SdmValoraci
13:13:47,444 DEBUG org.hibernate.engine.IdentifierValue,main:104 - id unsaved-value: null
13:13:47,444 DEBUG org.hibernate.engine.Cascade,main:115 - processing cascade ACTION_SAVE_UPDATE for: xx.xxxxx.xxxxxx.model.SdmValoraci
13:13:47,444 DEBUG org.hibernate.engine.CascadingAction$5,main:216 - cascading to saveOrUpdate: xx.xxxxx.xxxxxx.model.SdmEve
13:13:47,444 DEBUG org.hibernate.event.def.AbstractSaveEventListener,main:514 - transient instance of: xx.xxxxx.xxxxxx.model.SdmEve


Last edited by Chemi on Thu Feb 19, 2009 12:07 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:39 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
It seems like you have not linked your objects correctly. Check that you have assigned both ends of the association. For example:

Code:
SdmValoraci valoraci  = ...
SdmEve eve = ...
valoraci.setSdmEve(eve);
eve.setSdmValoraci(valoraci);
// and similar for the other one-to-one associations


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 19, 2009 8:41 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
It seems that sdmValoraci is null when you save SdmValoraci.

Also, you should mark your one-to-one with constrained="true", as the association is obviously needed for a pk.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 01, 2009 1:28 pm 
Newbie

Joined: Thu Feb 19, 2009 8:06 am
Posts: 5
Thank you nordborg. Problem is solved ;)


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.