Recently I start to build an sub system for MIREX submission. It is not too complicated, it should accept submission of programs with certain metadata, such as contributors, notes, etc... And Mirex runner (NEMA system, or a human runner) should be able to change the status, leave note and inform the submitter. It is not simple when you need to consider every detail. And I have already spent about two weeks on it.
One thing I need to learn is Hibernate. We used that already in our system. But Amit and others have implemented it and provided me with a DAO object. So I have no direct interaction with it. This time, I have to write every bit from the scratch. Well, that is not totally true. I have their old code for reference. I use the annotation mapping, and spring hibernate template. I spent quite some time to read "
Java Persistence with Hibernate", not the best choice. The book was written by one of the authors of Hibernate, and is very detailed and not really good for the first-timer. After couple of days, I finished about half the books and started to read the
hibernate documentation from their site. It turns out much more accessible. It has some good example and explains things pretty clearly and I really like it.
Today, I realize that I need to have bi-direction many-to-one and many-to-many association with list. The order is important. I looked though the book and again, the documentation gives me an easier answer.
@OrderColumn
. And here comes the problem. We are using a quite mixed version of hibernate, some modules use 3.2.6, some uses 3.3.0GA and some use 3.4.0GA, with JPA 1. None of them support @OrderColum. It took me a while to figure out that this is the new annotation for JPA2. I have to upgrade hibernate in order to use this feature. Otherwise, I can use some hibernate annotation. I figured to whatever, just upgrade. So the latest 3.5.1Final we go.
The first problem I run into is that I cannot find it in the main
maven repoistory. After some search, I found it is only in
JBoss's repository. I need to add it into our own proxy repository server. I have to ask Amit for the username/password for it. After some talk, I found out we have already had it in the proxy list. I SHOULD HAVE tried before ask...
And soon, I found the module structure changes. Hibernate-annotation depends on hibernate-core. So I only need to include hibernate-annotation. But soon I run into the next problem, Spring cannot build the session-factory for Hibernate, it cannot find some classes about slf4j. I am confused. Hibernate already has slf4j dependence. After some 20 minutes on google, I finally figured out that Hibernate has slf4j-api. But I also need to make my code depends on slf4j12. So include it and I got new different error.
This time is ehcache. The old code has
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
. I looked at hibernate-core.jar, and sure, it dose not have such class. After a while, I realized it might not in core. I check the repository, there is one module, hibernate-ehcache. Here we go. But again, new problem pops up.
It is something about assistance. I am confused again. Hibernate does have dependency on javaassistence. A close look says that is is in test scope. Maybe that is the reason. Add the new dependency, and finally my unit tests sort of run.
My old database schema does not work with the new ordercolumn. The project has dependency on hibernate3-maven plug-in. I used to just copy their output ddl into mysql to generate the new database. But this time after I import the ddl, the test always tell me some field "note_Orders" is missing. I am really confused. I gives the @OrderColumn a new name. After run the maven test several times and I started to read the ddl more carefully and sure, the order columns are missing. WTF!!! Well, it turns out that hibernate3-maven plug-in depends on hibernate-3.4.0GA. It is probably does not understand this new annotation.
I add
hibernate.hbm2ddl.auto=update
into the hibernate config. And it seems to update my schema fine.
WHEW, quite some work!