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

PK generation and mapping

 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, can anyone please help me on this. I have the exact similar situation.
 
Arun Kumarr
Ranch Hand
Posts: 661
Eclipse IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
check this.
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Instead of one-to-one I have a many-to-one mapping : I can't use "constrained=true".
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Somak Dalui:
Instead of one-to-one I have a many-to-one mapping : I can't use "constrained=true".


In Many-To-one you can't have them share the PK, because in the many side you would have many records trying to have the exact same PK. breaks the rule of a PK being unique to one record only. It has to be either a FK in the many table, or use a join table in between the one and the many.

Mark
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let me be clear with my exact problem. I have a mapping like


While I am trying to update this it says "descrID cannot be null" (it is a not-null field in the database).So I guess the pk is generated by the custom-generator class but is not getting assigned to the foreign key (descrID).Is there any other attribute to be used or any mistake in the mapping ? Please help.

Note : Although it looks redundant but I have to keep a 'descrID' field in the Java class as well. That is a requirement.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, now I understand your question.

So two things.

First you have this in your many-to-one. 'formula="descrID"' You do not need this.

Also in your code, you need to set both sides of the relationship. You need to add the BasisRuleDescriptorModel object to your Collection and set the AttributeDescriptorModel in your BasisRuleDescriptorModel object.

Also, there isn't an "all-delete-orphan" cascade option. I think you want "all, delete-orphan" as your cascade option.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic