wood burning stoves 2.0*
The moose likes EJB and other Java EE Technologies and the fly likes CMR & DB Foreign Key references Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "CMR & DB Foreign Key references" Watch "CMR & DB Foreign Key references" New topic
Author

CMR & DB Foreign Key references

Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
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

Joined: Mar 27, 2004
Posts: 401
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.


Leandro Melo
SCJP 1.4, SCWCD 1.4
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
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

Joined: May 29, 2003
Posts: 1258
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.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Sudharsan Govindarajan
Ranch Hand

Joined: Jul 03, 2002
Posts: 319
Thanks Nat!
I gotta consult my JBoss manuals. IMHO, enforcing referential integrity in the business logic is a pain

-Sudharsan
 
 
subject: CMR & DB Foreign Key references
 
Similar Threads
Proble with Relationship in Entity Bean
problem with inser into query
phpbb2jforum problem: Data too long for column 'user_timezone'
Caused by: com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException
Slow Queries