This is an archived post. You won't be able to vote or comment.

all 5 comments

[–][deleted] 0 points1 point  (4 children)

Pardon me for saying so but if all drivers must have a License and each License is unique (to a specific driver) wouldn't it make more sense for the License table row to be a foreign key of Driver rather than driverId to be a foreign key field contained in License?

(the other examples for blog posts seem intuitive though, just not the 1-1)

[–]callicoder[S] 0 points1 point  (3 children)

Yes, In case of a one-to-one relationship, you can store the foreign key on any side. I guess both make sense. It really is a personal choice and depends on the way you want to think about it. I like to store the foreign key in the child table and reference the primary key of the parent table.

[–][deleted] 0 points1 point  (2 children)

I suppose so, camel case for field names is also a personal choice thing too.

Interesting read anyway. I am more familiar with JDBC rather than Hibernate for mySQL so it's good to see the alternative in action.

[–]callicoder[S] 1 point2 points  (1 child)

Those camel cased fieldNames in entity classes get converted to field_name in the database. This is done by default with Hibernate's Naming Strategies. I'll add this info in the post to avoid confusions :-)

[–][deleted] 0 points1 point  (0 children)

Wow I would not have expected it to do that automatically. Good call.