You are so correct about doing homework first...It is the most efficient path.
Somehow I can't just go through this book (only EJB 2.1) with a EJB3 capable toolset on hand, without wanting to see if I can get it working the new way. Although this book has a lot of wisdom about how to develop web applications, having it written with old WTP and old EJB versions is a serious disadvantage. I think it actually makes it worse when they "tease" with only a few sentences that indicate you can get newer versions of your toolset and make the example project work there, and it will be so much cooler. I guess I'll just have to get a true EJB3 book ;)
In the mean time, I did get one more iteration of the project working. But, like the earlier version, I don't think the EJB3 stuff is right (an @Resource seems not to do anything). But most of what I was up against this time was using mysql instead of Derby, and the current Geronimo instead of (whatever they used in the book). I'm going to take this topic down a winding path now by laying out how to get this iteration working on Geronimo. The project has a little Hibernate stuff in there that I've just started with (not to be considered at all correct). The project works, albeit not using hibernate.
Here's the project:
Place to download Eclipse WTP Ch 8 Iteration 3 For Ganymede, Geronimo, MySql I used Geronimo 2.1 as my container, and I used mysql as a database for this project. It seems that you MUST start Geronimo, log into the admin console (username:system, password:manager),and create a database pool (I called mine "jdbc/MyDataSource"). It seems that just putting the mysql connector jar (with the com.mysql.jdbc.Driver class) in the xml deployment descriptors is not enough. A database pool is required. I actually placed the mysql connector jar file in the appropriate directory under "repository" before creating the pool. Then, after you have configured the databse pool, you can click "Usage" from the list of pools, and it will tell you exactly what needs to be in web.xml and geronimo-web.xml.
Also, The maven-style paths under "repository" can be troublesome. Your jar file needs to have a version number on it (ie mysql-connector-java-5.1.7.jar). If you defined your "groupId" as "mysql", then under "<GERONIMO_HOME>/repository/", you would have a "mysql" directory (if you are unfortunate enough to name your "groupId" "com.my.stuff", you would need to nest "com/my/stuff"). Inside of "mysql", you need to create a directory matching the "artifactId", and inside of that, you need to make a directory matching the version (in this case "5.1.7"). Finally, you put your jar file in there. So we have:
"<GERONIMO_HOME>\repository\mysql\mysql-connector-java\5.1.7\mysql-connector-java-5.1.7.jar"
I'm sure glad this is simplified to such a great extent!
Now, you would think that the following dependency would work:
.... but you would be WRONG!
You need to include things something like this in the geronimo-web.xml:
...
and in web-xml:
(as I mentioned above, the Geronimo Console will give you these details after you define the pool).
Here are some of the things I saw in my trials, for the googlers of the world:
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
Missing dependency exception
Unable to resolve resource reference res-ref-name
Missing dependency: mysql/mysql-connector-java
java:comp/env/jdbc resource-ref
--Dale--
[ November 23, 2008: Message edited by: Dale Seng ]