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.  [ 2 posts ] 
Author Message
 Post subject: Update SQL using all tables fields in where clause
PostPosted: Mon Jun 08, 2009 1:07 pm 
Hi everyone.

I don't know what I'm doing wrong.
When I update an object in my database, I got a strange SQL statement. For example.

Code:
<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="C0770_CONJUNTURA"
                   namespace="C0770_CONJUNTURA.modelo">

  <class name="myObject"
         table="myTABLE"
         optimistic-lock="all"
         dynamic-update="true">

    <id name="codigo" column="FIELD" type="Int32">
      <generator class="sequence">
        <param name="sequence">Seq_ID</param>
      </generator>
    </id>

    <property name="id"
        column="FIELD"
        type="Int32" />
     
    <property name="field1"
              type="double"
              column="FIELD"
              length="8"
              update="false" />

    <property name="field2"
              type="Int32"
              column="FIELD"
              length="2"
              update="false" />

    <property name="field3"
              type="Int32"
              column="FIELD"
              length="2"
              update="false" />


The UPDATE SQL generate is

UPDATE TABLE myTABLE SET id = p0, field1 = p1, field2 = p2, field3 = p3
WHERE
codigo = p4 AND
id = p5 AND
field1 = p6 AND
field2 = p7 AND
field3 = p8

Does NHibernate should't use only the primary key (codigo) field in UPDATE?
Why is it using all fields?

Tks


Top
  
 
 Post subject: Re: Update SQL using all tables fields in where clause
PostPosted: Tue Jun 09, 2009 1:37 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
There's no need for defining the id as a separate property (it's even an error), so remove:

<property name="id"
column="FIELD"
type="Int32" />

from the mapping. And maybe your combination of dynamic-update=true and setting all properties to update=false is confusing hibernate.

_________________
--Wolfgang


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.