Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Upgrading to Spring 1.2 RC1 and Hibernate 3.0

I spent an hour or so on Friday upgrading Equinox and AppFuse to use Spring 1.2 RC1 and Hibernate 3.0. The upgrade for AppFuse was relatively painless, but the upgrade for Equinox failed. Equinox uses HSQLDB version 1.7.1. The main reason I use the 1.7.1 version is to avoid the infamous "lock exception" that the new HSQL version throws in standalone mode. With version 1.7.1, it seems you could have more than one connection open to the file-based database w/ no problem. I really like this feature in 1.7.1 b/c it means you can run the app in Tomcat and browse the database at the same time.

So what's the problem? Why can't I just use Hibernate 3.0 with HSQL 1.7.1? The problem is I like using the following setting as part of my "sessionFactory" bean:

<prop key="hibernate.hbm2ddl.auto">update</prop>

This setting will update the schema when you change mapping files, but otherwise leave the data intact. Furthermore, it'll actually create the tables if they don't exist. Not so with Hibernate 3. With Hibernate 3, using "update" doesn't create the tables. Of course, upgrading to a newer version of HSQL fixes the problem, but then I get the lock problem. My eventual solution will probably be to hack Hibernate or HSQL, but for now I just won't upgrade Equinox. Another solution might be to look at some other embedded databases. Of course, I could also require users to install a database to run Equinox - but I like having the "no setup required" feature.

Regardless of the problems I experienced with HSQL and Hibernate 3, upgrading AppFuse was pretty painless. Here's the set of instructions I sent to the mailing list:

  1. Download Hibernate 3.0 and Spring 1.2 RC1.
  2. Create a lib/spring-1.2-rc1 and put the following files in it (NOTE: spring.jar now contains aopalliance.jar):
        acegi-security-0.8.1.jar
        commons-codec.jar
        ehcache-1.1.jar
        license.txt
        spring-mock.jar
        spring.jar
  3. Create a lib/hibernate-3.0 and put the following files in it:
        hibernate3.jar
        lgpl.jar
        lib/antlr-2.7.5H3.jar
            antlr.license.txt
            asm.jar
            c3p0-0.8.5.jar
            c3p0.license.txt
            cglib-2.1.jar
            dom4j-1.5.2.jar
            jta.jar
            jta.licence.txt
            oscache-2.1.jar
            swarmcache-1.0rc2.jar
  4. Change the versions for Hibernate and Spring in lib/lib.properties. Also, change the hibernate.jar property to reference hibernate3.jar instead of hibernate2.jar.
  5. In build.xml, change the "package-web" target to include all the Hibernate JARs instead of just specific ones:
    <lib dir="${hibernate.dir}/lib" includes="*.jar" excludes="jta.jar"/>
  6. Change web/common/taglibs.jsp to use uri="/oscache" for the oscache taglib.
  7. Search for "net.sf.hibernate" and replace it with "org.hibernate".
  8. Search for "orm.hibernate" and replace it with "orm.hibernate3" (for Spring).

The major difference for Hibernate is you no longer need odmg-3.0.jar, but you do need asm.jar and antlr-2.7.5H3.jar. Let me know if you find any issues with these instructions. You could also just download AppFuse from CVS.

NOTE: The CVS version of AppFuse has an XDoclet version that only supports generating Hibernate 2.x mapping files. I believe there is support for Hibernate 3 in XDoclet's CVS - but I haven't had a chance to upgrade yet.

Update: Here's more on the HSQL bug that's not really a bug (according to a comment on the post). Regardless of whether it's a bug or not, it'd be nice to have the 1.7.1 behavior as an option - it's a great feature for get-started-quick apps like Equinox.

Posted in Java at Apr 03 2005, 06:52:52 PM MDT 9 Comments
Comments:

Matt, I am doing upgrading Trails similarly, and ran across an XDoclet patch that generates Hibernate3 hbm.xml files. It's at: http://opensource.atlassian.com/projects/xdoclet/browse/XDT-1257 It seems to work so far, couple of things are missing (insert and update attributes don't seem to work). Have fun! --Chris

Posted by Chris Nelson on April 03, 2005 at 08:01 PM MDT #

Thought you're still recovering? Thank you for more on AppFuse, Mr. Raible. By the way, can you provide simpler math question on posting?

Posted by Vui Lo on April 03, 2005 at 11:22 PM MDT #

At least you got a response... No response for me on the Hibernate forums... This is following no response to 2 emails to the list and 2 posts to the forums for an issue with Spring. What's wrong with these opensource people? ;-)

Posted by Jason Carreira on April 04, 2005 at 11:34 AM MDT #

Remember to change your .build.properties file in you home directory should you have a .build.properties there. Hibernate dialect needs to be changed from net.sf.hibernate to org.hibernate.

Posted by sib on April 04, 2005 at 12:32 PM MDT #

I'm not sure that updating the schema automatically is even a good idea. In real life changes to the DB schema are normally very carefully controlled since the database generally has a longer lifecycle than the applications. For some people (like me) it may also be confusing. I must admit to skimming my way through the first few chapters of Spring Live - using it more like a base for my own experiments than gospel. I was confused by the schema update thing since I expected inserts from my experiments to persist in the database independent of whether I was running the Spring Live code or not. At first I thought that something in the Spring Live code was actively deleting from the database. Later I traced it back to the schema update. If database schemas really do need to be changed then adding explicit "ant" tasks is probably better. Hope it helps, Richard

Posted by Richard Sullivan on April 05, 2005 at 09:34 AM MDT #

Richard - I agree with you that automatic schema updates are not needed (and can be dangerous) in a real-world development situation. I don't know if it's worth the effort to refactor the first half of Spring Live to use Hibernate's SchemaExportTask though. I'll have to ask current Equinox users and Spring Live readers to see what the general consensus is.

Posted by Matt Raible on April 05, 2005 at 11:26 PM MDT #

Hi, Matt. I made a plugin which generates Hibernate3 hbm files for XDoclet2. Now this plugin used in our project sucessfully. I can share the code if you want. Probably you should move to XDoclet2?? As plugin writer I would say that XDoclet2 much better then XDoclet.

Posted by Anatol Pomozov on April 07, 2005 at 09:51 AM MDT #

Thanks for letting me know Anatol. I've heard good (and bad things) about XDoclet2. The good is ease-of-use for plugin writers, the bad is lack of documentation (and user community). I believe XDoclet 1.x just added Hibernate 3 support, I just need to update the JARs in AppFuse.

The main reason I won't be moving to XDoclet2 anytime soon is because all the templates in AppFuse's AppGen are written using XDoclet 1.x's XDT templates. Ugly, but it works great!

Posted by Matt Raible on April 07, 2005 at 09:55 AM MDT #

Anyone have a maven project.xml which uses Spring Framework 1.2.1 and Hibernate 3.0.1 and XDoclet? I have tried the XDoclet2 implementation from CodeHaus.org...it was fine for some simple XDoclet..but seemed to break once using Hibernate Components, etc. Thanks in advance

Posted by javapda on June 14, 2005 at 11:06 AM MDT #

Post a Comment:
  • HTML Syntax: Allowed