-->
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: fix for NonUniqueObjectException with int id
PostPosted: Fri May 14, 2004 8:22 am 
Newbie

Joined: Thu May 13, 2004 8:54 am
Posts: 2
I've set the "unsaved-value" to -1 and initialized the int id with -1 like this:

package test.data.hibernate;

Code:
/**
* @hibernate.class
*   table = "client"
*/
public class Client{
  [b]private int id = -1[/b];
  private String name;
 
  /**
   * @hibernate.property
   */
  public String getName() {
    return name;
  }
 
  public void setName(String model) {
    this.model = model;
  }
 
 
  /**
   * @hibernate.id
   *   generator-class = "increment"
   *   [b]unsaved-value = "-1"[/b]
   */
  public int getId() {
    return id;
  }
 
  public void setId(int id) {
    this.id = id;
  }
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 14, 2004 11:19 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
To avoid NonUniqueObjectException try before saving/updating to remove the object from the session:
Code:
session.flush(); // flush changes into the database

session.evict(yourObject); // remove the object from the session cache
//or
session.clear(); // clear the full session cache

// and then
session.saveOrUpdate(yourObject);


Leonid


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.