Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Object Relational Mapping and the fly likes Edit primary key, if it's a foreign key Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Edit primary key, if it Watch "Edit primary key, if it New topic
Author

Edit primary key, if it's a foreign key

Hajdu Attila
Greenhorn

Joined: Mar 05, 2010
Posts: 6
I have a problem: I can't know, how edit primary key, if this key is a foreign key...
ER:

I want to edit curseId, but I can't...

User.java


Curse.java


CurseId.java


UserCurse.java


UserCurseId.java


Thanks for helping!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

(Off-topic: are you keeping a list of the swear words the students use? ;) It's "course", not "curse" :)
Hajdu Attila
Greenhorn

Joined: Mar 05, 2010
Posts: 6
David Newton wrote:(Off-topic: are you keeping a list of the swear words the students use? ;) It's "course", not "curse" :)

Thank you for your comments! It's meaning course, of course :mrgreen:
OFF: My university have "NEPTUN" web based education system, and theme of my thesis is a same system. In NEPTUN, it's "curse"...
James Sutherland
Ranch Hand

Joined: Oct 01, 2007
Posts: 553
What do you mean by "edit", update?

You cannot update a primary key. You should delete the UserCurse object, and add a new one to the different Curse.

For an insert, you can just create the new UserCurse and set its Id.


TopLink : EclipseLink : Book:Java Persistence : Blog:Java Persistence Performance
Hajdu Attila
Greenhorn

Joined: Mar 05, 2010
Posts: 6
James Sutherland wrote:What do you mean by "edit", update?

Simple update courseId, for example...

Before:
Curses
curse_id semester_id ....
old 2010
old2 2010

Users_curses
curse_id semester_id user_id ...
old 2010 shark300

After:
Curses
curse_id semester_id ....
new 2010
old2 2010

Users_curses
curse_id semester_id user_id ...
new 2010 shark300

Any idea for editing Curse entity?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

As James points out, editing a primary key == inserting a new record. So I'd do what he's already suggested, delete the existing records and a a new one.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Hajdu Attila
Greenhorn

Joined: Mar 05, 2010
Posts: 6


This code don't create row in Users_Course... I know, if I create some new instances of UserCourse with "modifiedCourseId" courseId, rows are created.
But if this row is edited, I have to edit all instance in database, where courseId is "sub-primary key".

Any idea for editing Curse entity?
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

What is a "sub-primary" key?
Hajdu Attila
Greenhorn

Joined: Mar 05, 2010
Posts: 6
Paul Sturrock wrote:What is a "sub-primary" key?


courseId is a element of multiple primary key of Checks table.

Check.java


CheckId.java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Edit primary key, if it's a foreign key
 
Similar Threads
JPA: Cascade delete for join tables with composite key
Outer join between 3 entities in HQL
using 2 @OnetoMany annoations in one Entity Class
Problem with onetomany relantionship with JPA
Problem with onetomany relantionship with JPA 2.0