File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

CMR & DB Foreign Key references

 
Sudharsan Govindarajan
Ranch Hand
Posts: 319
  • 0
  • 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
 
Leandro Melo
Ranch Hand
Posts: 401
  • 0
  • 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
  • 0
  • 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
 
Nathaniel Stoddard
Ranch Hand
Posts: 1258
  • 0
  • 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
  • 0
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic