Tuesday, March 6, 2007

JPA 101 on The ServerSide

Chapter 7 of JPA 101 is now available on TheServerSide.com. I've got some JPA related material I need to put on this site, so check back later today for the Maven 2 JPA archetype and some other stuff :-) If you are interested in purchasing this book, you can find it here at SourceBeat.com. Let me know what you think of the chapter.

3 comments:

NilsM said...

I have just started reading the chapter of your book posted on theserverside.com

First: You may have taken this from the JPA specifications but it's rather unrealistic:

SELECT DISTINCT o1
FROM Order o1, Order o2
WHERE o1.quantity > o2.quantity AND
o2.customer.lastname = ‘Smith’ AND
o2.customer.firstname= ‘John’

It will assume there is only one order with lastname Smith and firstname John.
The example should of course have used the primary key of Order - probably orderid or something similar.
For someone not very familiar with relational databases your example will easily be believed to work even if there are multiple orders with the given lastname/firstname.

Your examples after figur 7.2 are very hard to understand.
They would have been easier if you had included the real table definitions with all the fields of each table.
I am aware that your figures are commonly used, but they remain unclear for many users of relational databases. We do not draw these kinds of drawings. We relate to tables with fields and all fields are created equal. It's only when they are used in a join some fields become - I believe you call them association-fields.
I assume association-fields are something special in JPA, but they sure aren't all that special in a relational database except possibly when some are defined as a foreign key referencing the primary key of some other table.

Back tyo your figure 7.2
Are these figures Java objects. In that case is the topics field you say is in Forum a reference to a list or some other collection type?
Or do these figures also somehow describe the database tables.
Of course the database tables should have been included and you should have said a word or two about how they are related to the classes/objects - including a reference to some other part of the book probably.

Does the Forum table look something like this:
forumid integer primary key,
name varchar(x),
description varchar(x),
...

and the Topic table something like this:
forumid integer,
topicid integer,
content varchar(x),
subject varchar(x),
...
With forum and topics together as the primary key.

and Post like this:
forumid integer,
topicid integer,
postid integer,
content varchar(x),
editcount integer

Whatever it is it's hard to see what you can navigate across and what not. Across a collection you say. Do you mean if there is a one to many relationship? And then you must use join instead or what on earth are you talking about.
I will probably understand it when reading more and testing for myself, but I like books that are immediately understandable.

Regards
Nils Myklebust

Anonymous said...

On page 60 of JPA 101, you have a CAUTION about a bug in Hibernate if the discrimator type is CHAR. That was the sole reference in all of google to that bug, and you saved me hours of frustration. I want to include the JPA bug number in comments in our code so we can remove the workaround when the bug is fixed. Do you know the bug number?

Anonymous said...

Typo! I meant to say do you know the *JIRA* bug number?