-->
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.  [ 7 posts ] 
Author Message
 Post subject: Getting updates when I shouldn't be...
PostPosted: Tue Jan 10, 2006 2:50 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I have a single table, with a single PK, mapped to a single object...as plain vanilla as you can possibly get with hibernate...however...I am getting an update for every row that is selected...this is blowing my mind!

I'm simply calling a list of records inside of a single, open session & transaction and trying to display the results.

The class:

Code:
package com.bol;

import java.util.Date;

public class Order
{
   private long id;
   private long transporterId;
   private long pickListId;
   private String customerId;
   private Date orderDate;
   private Date sentDate;
   private String name;
   private String address1;
   private String address2;
   private String city;
   private String state;
   private String country;
   private String postalCode;
   
   public Order()
   {
   }

   public long getId()
   {
      return id;
   }

   public void setId(long id)
   {
      this.id = id;
   }

   public long getTransporterId()
   {
      return transporterId;
   }

   public void setTransporterId(long transporterId)
   {
      this.transporterId = transporterId;
   }

   public long getPickListId()
   {
      return pickListId;
   }

   public void setPickListId(long pickListId)
   {
      this.pickListId = pickListId;
   }

   public String getCustomerId()
   {
      return customerId;
   }

   public void setCustomerId(String customerId)
   {
      this.customerId = customerId;
   }

   public Date getOrderDate()
   {
      return orderDate;
   }

   public void setOrderDate(Date orderDate)
   {
      this.orderDate = orderDate;
   }

   public Date getSentDate()
   {
      return sentDate;
   }

   public void setSentDate(Date sentDate)
   {
      this.sentDate = sentDate;
   }

   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }

   public String getAddress1()
   {
      return address1;
   }

   public void setAddress1(String Address1)
   {
      this.address1 = address1;
   }

   public String getAddress2()
   {
      return address2;
   }

   public void setAddress2(String Address2)
   {
      this.address2 = address2;
   }

   public String getCity()
   {
      return city;
   }

   public void setCity(String city)
   {
      this.city = city;
   }

   public String getState()
   {
      return state;
   }

   public void setState(String state)
   {
      this.state = state;
   }

   public String getCountry()
   {
      return country;
   }

   public void setCountry(String country)
   {
      this.country = country;
   }

   public String getPostalCode()
   {
      return postalCode;
   }

   public void setPostalCode(String postalCode)
   {
      this.postalCode = postalCode;
   }
}


The hbm.xml file

Code:
<hibernate-mapping>
   <class name="Order" table="sr_order">
     <id name="Id" column="order_id" type="long" unsaved-value="0">
      <generator class="identity" />
    </id>
     <property name="TransporterId" column="transporter_id" />
      <property name="PickListId" column="inv_pick_list_id" />
      <property name="CustomerId" column="cust_id" />
      <property name="OrderDate" column="order_date" />
      <property name="SentDate" column="sent_date" />
      <property name="Name" column="to_name" />
      <property name="Address1" column="to_addr1" />
      <property name="Address2" column="to_addr2" />
      <property name="City" column="to_city" />
      <property name="State" column="to_state" />
      <property name="Country" column="to_country" />
      <property name="PostalCode" column="to_postalcode" />
   </class>
</hibernate-mapping>


The calling code

Code:
Criteria c = session.createCriteria(Order.class);
      
List<Order> orders = c.list();

for (Order o : orders)
{
   ....      
}


For SOME reason, an update is issued for every single record when this runs! What's up w/ that? Is it seeing the records as dirty? This makes no sense and is the ONLY class in my entire domain that is behaving like this...it just doesn't make sense to me.

I have another class that's structured EXACTLY the same way, called Customer...which when used like the Order object is above....doesn't do the updating!

Hibernate version: 3.1

Name and version of the database you are using: MSSQL 2000


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 4:49 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
Any ideas? Anyone? I'm seriously crunched for time or I'd just be more patient.

I RTFM, I followed instructions, but this one object is producing unexpected behavior.

I'm pressed for time and Hibernate has always worked good for me in the past...but I have no choice but to rip it out of my DAO and start using something else or just manually mapping the classes to data...which sucks...but I have about 30 min. to decide!

Any clues? Shots in the dark are also welcome!

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 4:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Is it possible that you're changing the still-persistant Orders in your for-loop? You don't need to call a save method in Hibernate, if objects are still in the session: just modifying them then committing/flushing will cause updates to be executed. To experiment with this, close your session after c.list() is called.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:14 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
tenwit wrote:
Is it possible that you're changing the still-persistant Orders in your for-loop? You don't need to call a save method in Hibernate, if objects are still in the session: just modifying them then committing/flushing will cause updates to be executed. To experiment with this, close your session after c.list() is called.


Yeah, I realize that...which is why I'm stunned...I'm not changing *anything* in the loop...nothing...nada.

Even if I comment-out the loop, the act of simply *calling* the data into the List makes this happen.

On a large number of records this causes my database to grind completely to a halt...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:30 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
BTW - It only fires the update one time. I can shut down the db server, shutdown tomcat, and start it all up again and run the app...the updates don't happen.

If I refresh the data from the production server down to my dev box...it happens again...just once.

This is worse than having something break off underneath your fingernail...argh!!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:49 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Unless you've got an event listener which is changing values as these Orders as they're being loaded, it must be something to do with the id. All I can suggest is that you debug into the hibernate code and see what is causing the update. You could set up a PreUpdateEventListener and have a look at the new and old values in the objects, that might go faster.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:54 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
I FIGURED IT OUT!!

Stupid Netbeans!

I'm using a nightly release of netbeans 5.0 (yeah, go ahead and kick me now)...which has been EXCELLENT up until this little BUG!

Anyhow...the Address1 and Address2 fields were being set to NULL, that's what all the updates were about.

THAT was happening because the parameters were misspelled for those two setters...but either Netbeans and/or the Java compiler didn't catch it and allowed the classes to build that way...so...once I fixed the spelling everything fell into place.

AHHH!! That kept me busy for almost two days!!!


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