Hi everybody,
I´m having a problem with nativeid and i don´t know if i am doing right.
I have a class called Aircraft that has an generated id. But its natural id is the serial number(Integer) and Model( a custom class) like below:
Code:
public class Aircraft{
@Id @GeneratedValue(strategy=GenerationType.AUTO,generator="COD_NS_AENV")
@Column(name="COD_NS")
private Integer id;
@Column(name="NUM_IDENT_NS_AENV")
@NaturalId
private Integer serialNumber;
@ManyToOne
@NaturalId
private Model model;
.
.
.
}
I load this class from an XML and save into the database, like this:
Code:
.
.
.
Aircraft aircraft= (Aircraft)xstream.fromXML(reader);
Session session = HibernateUtil.openSession();
Transaction t = session.beginTransaction();
session.saveOrUpdate(aircraft.getModelo());
session.saveOrUpdate(aircraft);
t.commit();
session.close();
It works fine for insert,but my problem is when I execute this code again with the same information, Hibernate inserts another aircraft. I want that Hibernate only updates the current registry.
I overrided the method equals() to test the serialNumber and Model attributes but it is never called.
I don´t know how to make Hibernate understand that an object with serialNumber and model are the NativeId.
Thanks in advance!
Alexandre