• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

CMR & DB Foreign Key references

 
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which is the best way to enforce referential integrity in the DB? Should I use CMRs or should I go for FOREIGN KEY constraints at the DB level? Do they complement each other or compete with?

I tired to go with DB FK constraints alone, but I get the following exception


Can somebody point me my mistake?

Thanks
Sudharsan
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't think anyone could try to point your mistake if you don't post some code ;-)

I thing that just by using CMR you don't guarantee integreity, you also have to do it yourself (or by configuration or by coding). I'd leave fk the referencial integrity problem to the db, i don't see much problem on that.

Anyway, i don't have much experience yet, but it's just an opinion.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Posting code might not help me even. (Anyways I have to post a lot of code) It is a conceptual problem and I need advice on how to do it.

Thanks
Sudharsan
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Blah blah ... so much arguing.

It's a simple problem. ejbCreate attempts to insert the record given only simple CMP fields and the primary key. CMR fields are set in ejbPostCreate -- which is done after the database field is inserted by the container. So, your referential integrity has already been violated, and the database won't allow the initial insert after ejbCreate to be successful.

There is another solution, however. I think that container-specific deployment descriptors may allow you to do something akin to what you want, but you would have to consult your server's documentation. Or you can try and enforce your referencial integrity through your business logic.
 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Nat!
I gotta consult my JBoss manuals. IMHO, enforcing referential integrity in the business logic is a pain

-Sudharsan
 
I'm gonna teach you a lesson! Start by looking at this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic