• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

PK generation and mapping

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi, can anyone please help me on this. I have the exact similar situation.
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
check this.
 
Somak Dalui
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of one-to-one I have a many-to-one mapping : I can't use "constrained=true".
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic