Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148343
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:15:51+00:00 2026-05-23T19:15:51+00:00

I´m having a problem with nativeid and i don´t know if i am doing

  • 0

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 native id is the serial number(Integer) and Model( a custom class) like below:

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:

.
.
.
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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:15:52+00:00Added an answer on May 23, 2026 at 7:15 pm

    Most likely Hibernate just uses @Id property and generates new value every time. That happens because you read your object from XML and id is not in XML, I assume. I don’t think natural id will coexist well with surrogate autogenerated id. And for saveOrUpdate Hibernate will just look at id to determine if object is new.

    Here is more details on Hibernate forums.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We are having problem with the server migration. We have one application that are
hey there i am having problem i have List<List<memoryCard>> that i want to show
I'm having problem when running my Windows Forms program. In the program, I have
m having problem in passing parameter to controller action, i have done the following
Hi I'm having problem refreshing my listview after Async operation. I have a simplecursoradapter,
i'm having problem when i want to select element using querySelector <ul class=xoxo blogroll>
I'm having problem with my class. I'm going to make comparision operators of my
I am having problem in django. I have created a form in my app
I am having problem filtering the mousePressEvent with installEventFilter MyTestxEdit is a widget that
i am having problem in installing provision it gies me error that A validcode

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.