I have been working with SmartFox Server Pro for about 3 months now. In those 3 months, I have had many ups and downs dealing with a relatively steep learning curve with respect to some of SmartFox’s quirks. I wanted to pass on what I have learned thus far to the community in hopes that it may help to facilitate more growth in this area with what seems to be a stellar product.
So let’s start with Hibernate …
As many of you know, Hibernate is an ORM (Object Relational Mapper). My purpose here is not to discuss how to use Hibernate (their community has done a phenomenal job of doing this for you already … I also recommend the fantastic book, Java Persistence with Hibernate … I would not have been able to learn Hibernate with out it), but to discuss what I have done to get it working with SmartFox. I want to start the discussion by explaining how I have SmartFox set up and it will help to understand why things need to go where I am going to tell you to put them.
SmartFox has two ways that it can be started, either through start.sh in the /Server folder or via the sfs start command. The sfs start command will use the Java Service Wrapper with the configuration file contained in /Server/config/wrapper.conf. I choose the latter simply because of the power that the Wrapper allows for (including debugging, which is indispensable when developing a SmartFox application). If you open this file and look around a bit, or are familiar with the Java Service Wrapper, you will find that it is chiefly responsible for defining Java’s classpath that is used when SmartFox starts up. The wrapper.java.classpath directive is extremely important. This brings us to the first configuration note that begins our journey to Hibernate happiness. There are 4 library (jar) files that are required to utilize all of Hibernate’s glorious features. Essentially you will make 4 separate entries in wrapper.conf that look like below:
wrapper.java.classpath.41=/opt/SFS_PRO_1.6.6/Server/lib/hibernate3.jar
wrapper.java.classpath.43=/opt/SFS_PRO_1.6.6/Server/lib/log4j-1.2.15.jar
wrapper.java.classpath.47=/opt/SFS_PRO_1.6.6/Server/lib/hibernate-annotations.jar
wrapper.java.classpath.48=/opt/SFS_PRO_1.6.6/Server/lib/javax.persistence_1.99.0.v200906021518.jar
wrapper.java.classpath.49=/opt/SFS_PRO_1.6.6/Server/lib/hibernate-commons-annotations.jar
wrapper.java.classpath.50=/opt/SFS_PRO_1.6.6/Server/lib/ejb3-persistence.jar
I must apologize at this point because I want to go off on a tangent for a moment. If you will notice there is a fifth entry there for log4j. I have not, despite countless hours and most of my hair now missing, been able to get log4j to properly work with Hibernate (or at all, for that matter). If anyone could leave a comment or contact me on the SmartFox server forums (starzero, is my name) on how to do this, I would be eternally grateful.
Please note that each wrapper.java.classpath entry has an integer value that is incrementing by 1. This is very important as it is a Wrapper convention (so, please follow it). Now, as you are no doubt aware, you will restart the SmartFox server with the command sfs restart (if you are new to SmartFox development and utilize a large body of Java based extensions, you will get used to restarting the server). Once the server is restarted each of those libraries will be available to you within your Zone or Room based extension. You are now free to create your Entities fire up your Sessions and control Transaction Demarcation to your database (sounds exciting, doesn’t it?)!
This has been a very short post, but thank you for reading it. It is my hope you learned something. I hope to put together many more of these including my development environment / methodology with SmartFox as well as a brief tutorial (with pictures) on how to debug your extensions (yes, this is covered in the forums, but may be helped with a bit more explanation).
Share on Facebook
Posted at 6:08 am on October 16th, 2009. 11 comments... »
Categories: Uncategorized. Tags: hibernate, java, smartfox.