This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JDBC and the fly likes 1-to-many data modeling. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "1-to-many data modeling." Watch "1-to-many data modeling." New topic
Author

1-to-many data modeling.

Silvio Esser
Ranch Hand

Joined: Nov 05, 2005
Posts: 58
I�m using Oracle 10g and trying to set an 1-to-many (1�m) constraint between two tables. The �many� means 1, 2, 3, � etc., not including 0. I know how to set foreign key constraint, but not this type of 1-to-many
(1, 2, 3, �) relation. Can anyone help?
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Silvio,

How would you insert a record in the parent table with this constraint?
- You can't enter a child record, because it violates the foreign key rule (the parent record does not exist).
- You can't enter a parent record, because you only allow parents with at least one child.

Regards, Jan


OCUP UML fundamental and ITIL foundation
youtube channel
Silvio Esser
Ranch Hand

Joined: Nov 05, 2005
Posts: 58
Is it possible to create an entry in the parent table first and then an entry in child table in the same transaction, and then commit?

I'm asking this question b/c many data modeling tools do support this
type of 1-to-many (1,2,3...M) relation.
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 2491
    
    8

Is it possible to create an entry in the parent table first and then an entry in child table in the same transaction, and then commit?
Yes, but your constraint would trigger before the commit.
Constraints are checked at insert/update/delete time, not at commit time.

Regards, Jan
[ May 19, 2007: Message edited by: Jan Cumps ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
You cannot enter a foreign key if there is no entry in the "parent" table corresponding.
You cannot enter in the "parent" table if you insist on there being a "child" first.
You have set yourself an impossible task.

For a very short time, after entering your "parent" table line and before entering your "child" table line, you are going to have to live with a 0..* (zero-to-many) relation.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 1-to-many data modeling.
 
Similar Threads
Question about Dueling auth-constraint elements
Operator precedence
Combining Security Constraints
what is the Output? and why?
A Dan Mock Exam Question (Dec 4)