• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Edit primary key, if it's a foreign key

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(Off-topic: are you keeping a list of the swear words the students use? ;) It's "course", not "curse" :)
 
Hajdu Attila
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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"...
 
Ranch Hand
Posts: 553
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

 
Hajdu Attila
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Hajdu Attila
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is a "sub-primary" key?
 
Hajdu Attila
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Sturrock wrote:What is a "sub-primary" key?



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

Check.java


CheckId.java
 
Everybody! Do the Funky Monkey! Like this tiny ad!
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic