Problem with sfs extension using JPA

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

tai65535
Posts: 3
Joined: 04 Jan 2018, 02:21

Problem with sfs extension using JPA

Postby tai65535 » 04 Jan 2018, 02:57

Hi there,

I've been working on adding database functions to my smartfox extension.

I was able to connect to a MySQL DB and import an entity to my test project (which only has one sfsextension class with init() function and one generated model class), everything works great in the IDE (Eclipse, Netbeans, I tried both. I put my test function in the public static void main() when i tested it in the IDE)

So I moved my test function in init() and exported to a JAR, put it in {SFS}/extensions/myproj/myextension.jar and restarted SFS server,
Then I kept on getting: "Message: No Persistence provider for EntityManager named ..."
(I do realize if i put the wrong persistent unit name, i will get this error in the IDE as well)

I've been trying to figure this out for a day now, tried numerous of things and felt defeated:
- I made sure all the dependencies are in the __lib__ folder, actually if they are not, SFS will throw the "NoClassDefFoundErr"
- I've been playing with the persistence.xml settings. I also unzipped the .jar, it's there for sure
- I tried resetting build file, class path, etc., which didn't really help
- Even tried manually update some fields/URL in persistence.xml, cuz people say they could cause troubles.
- Some people also say should use some other classes for EntityManager class, i doubt if that's the cause of it since i am using a new version of the tool chain.

Could it have something to do with the JRE version that smartfox (2.13.0) is using? I am using a different JRE version for the IDE for sure. (Copy and replace the jre folder in smartfox folder will make SFS unable to start sometimes.)
Or should i try a different persistent provider? (I used EclipseLink/org.eclipse.persistence.jpa.PersistenceProvider, i saw many people are using Hibernate.)
Maybe the smartfox main process can ignore some settings of the extension?
Does it have something to do with the thread model or loader thing?

Would be great if someone can show me a working example (Any persistence service is fine).
Please, shed some lights on me;P
Tai
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with sfs extension using JPA

Postby Lapo » 04 Jan 2018, 08:43

Hello,
have taken a look at this tutorial?
http://smartfoxserver.com/blog/integrat ... server-2x/

It walks you through all the steps to setup a basic JPA example. Maybe you're missing some steps.

As regards the JRE version I doubt it could make any difference. SFS2X runs with any Java 8, so unless you're running something older I wouldn't expect any issues.

My memory on JPA is a little fuzzy. Does the "No Persistence provider" error appear if the persistence.xml file is not found? Or do you get another error...

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
tai65535
Posts: 3
Joined: 04 Jan 2018, 02:21

Re: Problem with sfs extension using JPA

Postby tai65535 » 04 Jan 2018, 18:55

Woohooo! I figured it out, this META-INF folder (which contains the persistent.xml) has to go right under SFS2X; the META-INF folder in my extension jar will not be read.
META-INF.PNG
(26.28 KiB) Not downloaded yet


Thanks for the post. I was able to export all my model files in a separate jar and put it in __lib__ under extensions folder.

It's working now;)

Tai
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem with sfs extension using JPA

Postby Lapo » 05 Jan 2018, 08:32

Great! :)
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: Google [Bot] and 52 guests