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: NHibernate Composite Key Insert Problem... :(
PostPosted: Sun Feb 10, 2008 4:42 pm 
Newbie

Joined: Tue Oct 16, 2007 4:45 pm
Posts: 6
Hello,

i have a problem with a composite key, i dont know if i must to put any extra code, but i cant get it working...


if i change the database and the mappings to an autonumeric key, it works perfectly, but the key is a composite key...

can someone show me a way to accomplish this??

thanks!!!

Hibernate version:
NHibernate 1.2

Mapping documents:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<!-- Generated by ObjectMapper 09/02/2008 17:34:54. http://www.puzzleframework.com -->
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" schema="dbo">
  <class name="MySurvey.Data.NH.Respuesta, MySurvey.Data.NH" table="Respuesta">
    <composite-id>
      <key-many-to-one name="idPregunta" class="MySurvey.Data.NH.Pregunta, MySurvey.Data.NH" column="idPregunta" />
      <key-many-to-one name="idUsuario" class="MySurvey.Data.NH.Usuario, MySurvey.Data.NH" column="idUsuario" />
    </composite-id>
    <many-to-one name="idRespuestaPosible" column="idRespuestaPosible" class="MySurvey.Data.NH.RespuestaPosible, MySurvey.Data.NH" />
    <property name="respuestaFecha" column="respuestaFecha" type="DateTime" />
    <property name="respuestaNumero" column="respuestaNumero" type="Double" />
    <property name="respuestaTexto" column="respuestaTexto" type="String" />
  </class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
Code:
NH.Respuesta res = new MySurvey.Data.NH.Respuesta();
                res.idUsuario = NHibernateHelper.Instance.getSession().Get<NH.Usuario>(idUsuario);
                res.idPregunta = NHibernateHelper.Instance.getSession().Get<NH.Pregunta>(idPregunta);
                if (idRespuestaPosible != null)
                    res.idRespuestaPosible = NHibernateHelper.Instance.getSession().Get<NH.RespuestaPosible>(idRespuestaPosible);
                res.respuestaTexto = respuestaTexto;
                if (respuestaNumero != null)
                    res.respuestaNumero = (long)respuestaNumero;
                if (respuestaFecha != null)
                    res.respuestaFecha = (DateTime)respuestaFecha;

                NHibernateHelper.Instance.getSession().SaveOrUpdate(res);

Full stack trace of any exception that occurs:
Not Exception at all.
Name and version of the database you are using:
SQL 2000
The generated SQL (show_sql=true):
no insert code generated.

Debug level Hibernate log excerpt:
???


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.