Page 1 of 1

SFS 2x and Hibernate help

Posted: 12 Dec 2010, 16:55
by dragagon
Hey everyone,

So I've been trying for several hours to get hibernate to work with SFS2x and was wondering if anyone else has had any luck and what steps you tried in order to get it to work.

My problem is that I see the lib directory for SFS2x and I notice that the jar file versions are different, in some cases they are different by a major release number. I've tried a few different things from making all jar files the latest version, to putting the hibernate specific jars in the __lib__ directory, to putting everything into the extension directory and I've hosed it so bad I'm now reinstalling SFS2x and Netbeans to get back to a base configuration.

Does anyone have a working set of jars and locations that could help out. I've read the forums over and over but everyone I see is using 1.6, not 2x. I'm going to keep playing with it, but if anyone has any insight into which jar files and where they should live, I'd appreciate it.

Posted: 13 Dec 2010, 08:21
by Lapo
Does Hibernate have dependencies that overlap with the SFS2X ones?
If so which ones?

In general we recommend to put all dependency jars together with the extension jar file in the Extension folder. This way classes are loaded inside the Extension classloader and won't affect anything else in the system.

Advantages: no collisions with other classes
Disadvantages: each extension restart will reload all dependency classes

If I recall correctly Hibernate also points to some external resource files. These files should be seen in the classpath in order to be loaded by the library. The default classpath points to the SFS2X root folder, so you should drop there any other external files.
If you want to use another directory you will have to create it and add it to the classpath.

Posted: 13 Dec 2010, 12:58
by KlingOne
I've got hibernate working with 2x.
It basically works the same way it does with 1.6.
All the hibernate libs need to go directly into the SFS2X\lib directory and every class file that gets persisted via hibernate needs to be in SFS2X\{YourPackageHirarchy}

Posted: 13 Dec 2010, 13:02
by Lapo
and every class file that gets persisted via hibernate needs to be in SFS2X\{YourPackageHirarchy}
I don't understand... maybe you mean that they go under the extensions/{your-ext-name}/ folder?

Posted: 13 Dec 2010, 13:19
by KlingOne
No, I mean if hibernate persists MyClass and MyClass is in the package com.persistable then the MyClass.class needs to be put into SFS2X\com\persistable\

at least thats the only way I managed to get hibernate to find the class files

Posted: 13 Dec 2010, 13:46
by dragagon
The version of hibernate I was attempting to use is the one that came with Netbeans 6.9. Many of the Hibernate libs were older than the ones in SFS 2x. The most notable one that was not was sfl4j. I had put in 1.6.0, but in doing so, it broke sfl4j-log4j, so I had to go get the latest version for that which is 1.6.1 and just updated both.

I finally became frustrated enough with the thing not playing properly that I followed another post on here about using OpenJPA. I was able to set that up properly, so I moved on.

Posted: 13 Feb 2011, 11:32
by KlingOne
I wrote a short tutorial or the people that still have issues with hibernate and sfs2x.
http://klingonenblog.wordpress.com/2011 ... rnate-jpa/

Posted: 14 Feb 2011, 08:32
by Lapo
@KlingOne:
nice guide! I have reposted the link as another topic and made it a sticky.

Thank you

Posted: 14 Feb 2011, 08:36
by Lapo
@KlingOne:
One small note. In your article you say:
Since Smartfox uses a separate classloader for every extension, we need to copy this class file directly into the SFS2X folder in order to be able to keep a single Database connection for all of our extensions. The same is the case for all our classes we want to store in our database. Otherwise Hibernate won’t be able to find them.
It would be probably good to explain exactly which folder do you deploy the class files to. I guess in this case you mean the SFS2X/lib/ folder, right?