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:
???