Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

My App in NetBeans won't recognize a new Primary Key in my DB

 
Blake Edward
Ranch Hand
Posts: 105
4
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Initially, I created a DB that had a Primary Key of "employee_id". Everything was great until I realized that the DB would not accept input into the "employee_id" field from the admin tool. The admin tool is just an editor with a series of fields to be filled out or changed, then saved to the DB. Maybe there is way to do this, but as I researched it no legit relational DB would allow human input/error in the primary key column.

So, I created a new column in my DB that is called "dbid", and it is a self incrementing integer that now serves as the primary key.

In my application, I recreated my entity classes to match the new DB schema. But now when I try to change the "employee_id" in any row, which is no longer the primary key, I get this error:

Local Exception Stack:
Exception [EclipseLink-7251] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.ValidationException
Exception Description: The attribute [employee_id] of class [DBClasses.Spokespersons] is mapped to a primary key column in the database. Updates are not allowed.

As far I can tell, there is no code in my application that states the primary key is "employee_id". How do I fix this? Is there a jar file somewhere that needs to be changed/updated to match the new entity classes? Is this a NetBeans bug?

I can change any other field and successfully save it with no errors. But, since I need to install the "employee_id" of any new employee added to the DB I am unable to add new data to the DB.

Thanks in advance for any help anyone can provide.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you share the mapping of your entity, especially the field which is mapped as a primary key?
 
Blake Edward
Ranch Hand
Posts: 105
4
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:Can you share the mapping of your entity, especially the field which is mapped as a primary key?


I put the whole class in here, but really all you need to see is that "wwid" (which in the above post I referred to it as "employee_id") isn't mapped as the primary key anymore while "dbid" is. I recreated this class when I changed the primary key in my DB expecting the entire program to update along with it. I have scoured my application for any leftover code that still declares the "wwid" as primary key, but can't find any. My concern is that there is some metadata, a jar file, something else that still thinks my primary key is "wwid". The DB doesn't think this but the program I am building does.

 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blake Edward wrote:I put the whole class in here, but really all you need to see is that "wwid" (which in the above post I referred to it as "employee_id") isn't mapped as the primary key anymore while "dbid" is. I recreated this class when I changed the primary key in my DB expecting the entire program to update along with it. I have scoured my application for any leftover code that still declares the "wwid" as primary key, but can't find any. My concern is that there is some metadata, a jar file, something else that still thinks my primary key is "wwid". The DB doesn't think this but the program I am building does.

So let's see if I understand your issue correctly. In a previous version of the application you used "wwid" as a primary key for the Spokespersons entity. But then decided that "dbid" is a much better choice. But now you get an exception when trying to update "employee_id" which is no longer a primary key anymore.

First of all, it's very confusing that you get an error on The attribute [employee_id] of class [DBClasses.Spokespersons], but that employee_id is not used at all in the entity class you just have shared. So it seems your application might be using an old version of this class. If that's not the case, could you share the actual error you currently get (which should complain about an attribute of the current class).

Secondly it seems you have a setDbid method in your entity. The primary key is generated by the database (according to the @GeneratedValue annotation). So you are definitely not setting the primary key explicitly when updating/creating an existing/new entity. Because some persistence providers don't like if you are updating the primary key (which makes sense in my opinion).

I'm not an EclipseLink expert (have been using Hibernate all the time), but maybe it's somehow related to the same issue described here.

Hope it helps!
Kind regards,
Roel
 
Blake Edward
Ranch Hand
Posts: 105
4
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:
Blake Edward wrote:I put the whole class in here, but really all you need to see is that "wwid" (which in the above post I referred to it as "employee_id") isn't mapped as the primary key anymore while "dbid" is. I recreated this class when I changed the primary key in my DB expecting the entire program to update along with it. I have scoured my application for any leftover code that still declares the "wwid" as primary key, but can't find any. My concern is that there is some metadata, a jar file, something else that still thinks my primary key is "wwid". The DB doesn't think this but the program I am building does.

So let's see if I understand your issue correctly. In a previous version of the application you used "wwid" as a primary key for the Spokespersons entity. But then decided that "dbid" is a much better choice. But now you get an exception when trying to update "employee_id" which is no longer a primary key anymore.

First of all, it's very confusing that you get an error on The attribute [employee_id] of class [DBClasses.Spokespersons], but that employee_id is not used at all in the entity class you just have shared. So it seems your application might be using an old version of this class. If that's not the case, could you share the actual error you currently get (which should complain about an attribute of the current class).

Secondly it seems you have a setDbid method in your entity. The primary key is generated by the database (according to the @GeneratedValue annotation). So you are definitely not setting the primary key explicitly when updating/creating an existing/new entity. Because some persistence providers don't like if you are updating the primary key (which makes sense in my opinion).

I'm not an EclipseLink expert (have been using Hibernate all the time), but maybe it's somehow related to the same issue described here.

Hope it helps!
Kind regards,
Roel


I apologize for the lack of clarity. I am not supposed to be sharing any code with the public so I initially changed wwid to a more generic term: employee_id. But I get no support at work. Honestly, it just doesn't matter any more so this time I gave you the real entity class that uses the real previous primary key: wwid.

The link you sent is probably the answer to my problems. I will let you know how this turns out before morning. It is my son's Birthday, so we are treating him to a special outing, dinner at the restaurant of his choice, etc. So it'll be a late night. Thanks for the link!
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blake Edward wrote:It is my son's Birthday, so we are treating him to a special outing, dinner at the restaurant of his choice, etc. So it'll be a late night. Thanks for the link!

Happy birthday to your son Have an awesome time out!
 
Connor Van Elswyk
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you updated the DB appropriately? Ie removed the PK from the old column and updated it with the new?

Does there error happen on start up or when you attempt an update?

Getter/setter should make a difference but it's best practice to have the id as the first field in the class.
 
Blake Edward
Ranch Hand
Posts: 105
4
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have done everything I can personally. This is my first big application and I work in a vacuum, meaning the people I work for don't understand or give a crap. It is a large enough company that my request for real help should have been pretty easy to supply. But no help was provided. My client is also my company's client, so I don't understand the lack of concern. In a way, I have been hung out to dry. I think IDE choice (NetBeans) was a mistake, but there were many, many more tutorials and info associated with it. Ultimately, I can handle taking the fall because it has been an incredible learning experience and I don't plan on being here much longer. I will never be a genius level programmer but I am stubborn and would thrive in the right team oriented environment.

Anyway, thanks for your post. Tomorrow is the day of the scheduled train wreck, Wish me luck.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blake Edward wrote:Tomorrow is the day of the scheduled train wreck, Wish me luck.

Best of luck, Blake! Yes, you can!
 
Blake Edward
Ranch Hand
Posts: 105
4
Java Netbeans IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Update: I could never resolve this issue. I read the threads and the Netbeans bug info and tried every fix I could think of. I tried remapping the entity classes, creating a new table and then remapping, creating a new library for my application... nothing worked. I asked for professional help from my company and never got the help I needed. I had some conversations with a few people that knew about coding but not about Java. In the end, as time was wasting away, I just rebuilt the application. I am beyond my sticking point and hopefully about to wrap it up. The job has exposed weaknesses at my work place, like lack of support and the willingness to sign contracts worth thousands and then leave the poor developer out in the cold. It has been harsh. My client has been great. I have been completely transparent about my obstacles, my limitations, my successes and also my company's lack of support. I almost got fired a few weeks ago for this. Almost done though. Thanks for all the help.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic