Hi,
Tried to include openJPA with SFS2X It seems to me like the persistence.xml file inside the jar located inside the META-INF folder cannot be found by OpenJPA, I used a test case inside Eclipse with the same project and everything goes green, db is reached and entries are made.
Here is the error :
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
>> Zone: xxx
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
08 nov. 2010 19:31:11,554 INFO [main] entities.managers.SFSZoneManager - Creating room: (default) The Lobby
08 nov. 2010 19:31:11,556 INFO [main] v2.api.SFSApi - Room created: [ Room: The Lobby, Id: 1, Group: default, isGame: false ]
08 nov. 2010 19:31:11,578 INFO [main] Extensions - {xxxGame}: LumeGame : Testing JPA
08 nov. 2010 19:31:12,241 ERROR [main] entities.managers.SFSExtensionManager -
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: org.apache.openjpa.persistence.ArgumentException
Message: A JDBC Driver or DataSource class name must be specified in the ConnectionDriverName property.
Description: Extension initialization failed.
+--- --- ---+
Stack Trace:
+--- --- ---+
org.apache.openjpa.jdbc.schema.DataSourceFactory.newDataSource(DataSourceFactory.java:76)
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.createConnectionFactory(JDBCConfigurationImpl.java:839)
org.apache.openjpa.jdbc.conf.JDBCConfigurationImpl.getDBDictionaryInstance(JDBCConfigurationImpl.java:597)
org.apache.openjpa.jdbc.meta.MappingRepository.endConfiguration(MappingRepository.java:1489)
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:507)
org.apache.openjpa.lib.conf.Configurations.configureInstance(Configurations.java:432)
org.apache.openjpa.lib.conf.PluginValue.instantiate(PluginValue.java:104)
org.apache.openjpa.conf.MetaDataRepositoryValue.instantiate(MetaDataRepositoryValue.java:68)
org.apache.openjpa.lib.conf.ObjectValue.instantiate(ObjectValue.java:83)
org.apache.openjpa.conf.OpenJPAConfigurationImpl.newMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:939)
org.apache.openjpa.conf.OpenJPAConfigurationImpl.getMetaDataRepositoryInstance(OpenJPAConfigurationImpl.java:930)
org.apache.openjpa.kernel.AbstractBrokerFactory.makeReadOnly(AbstractBrokerFactory.java:639)
org.apache.openjpa.kernel.AbstractBrokerFactory.newBroker(AbstractBrokerFactory.java:206)
org.apache.openjpa.kernel.DelegatingBrokerFactory.newBroker(DelegatingBrokerFactory.java:156)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:227)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:154)
org.apache.openjpa.persistence.EntityManagerFactoryImpl.createEntityManager(EntityManagerFactoryImpl.java:60)
sfs2x.extensions.games.lume.LumeExtension.TestJPAConnexion(LumeExtension.java:49)
sfs2x.extensions.games.lume.LumeExtension.init(LumeExtension.java:33)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.createExtension(SFSExtensionManager.java:307)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.createZone(SFSZoneManager.java:395)
com.smartfoxserver.v2.entities.managers.SFSZoneManager.initializeZones(SFSZoneManager.java:220)
com.smartfoxserver.v2.SmartFoxServer.start(SmartFoxServer.java:193)
com.smartfoxserver.v2.Main.main(Main.java:31)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
com.exe4j.runtime.LauncherEngine.launch(Unknown Source)
com.exe4j.runtime.WinLauncher.main(Unknown Source)
com.install4j.runtime.launcher.WinLauncher.main(Unknown Source)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Any input on making this orm work would be nice. In fact is SFS2x made to work with orm's or should we stick to direct calls to the database ? it seems to me like using openJpa would help making asynchronous db operations more optimized.
[Solved] SFS2x and OpenJPA
[Solved] SFS2x and OpenJPA
Last edited by roychr on 09 Nov 2010, 14:45, edited 2 times in total.
I did what you said and unfortunately it did not work. I managed to make it work, here is the deal :
I found this url : http://openjpa.apache.org/builds/latest ... tence.html which specify the following statement
Now I splitted my code into two jars, one with the class/entities and I put this class inside the SFS2X/lib because they are unlikely to change much since they are data container and does not contain any code logic and they will be referenced by my extension. This is also important because OpenJPA will search for classes specified in persistence.xml (located now in SFS2X/META-INF folder) and I was unsure if the __lib__ folder is actually in the class path.
So now when I add a new class with anotations inside my persistence.xml as well as my system jar, database tables are created automatically if not present or updated to reflect code. I am still pretty noob with OpenJPA but Hibernate was too hard to integrate with SFS2X. Hope it helps people out using orm's for their projects !
I found this url : http://openjpa.apache.org/builds/latest ... tence.html which specify the following statement
So I placed the file in the SFS2X/META-INF folder, the root folder where the sfs2x-standalone.exe file is located is part of the class path. Strangely the SFS2X/lib/META-INF folder did not work.The createEntityManagerFactory methods search for persistence.xml files within the META-INF directory of any CLASSPATH element. For example, if your CLASSPATH contains the conf directory, you could place an EntityManagerFactory definition in conf/META-INF/persistence.xml.
Now I splitted my code into two jars, one with the class/entities and I put this class inside the SFS2X/lib because they are unlikely to change much since they are data container and does not contain any code logic and they will be referenced by my extension. This is also important because OpenJPA will search for classes specified in persistence.xml (located now in SFS2X/META-INF folder) and I was unsure if the __lib__ folder is actually in the class path.
So now when I add a new class with anotations inside my persistence.xml as well as my system jar, database tables are created automatically if not present or updated to reflect code. I am still pretty noob with OpenJPA but Hibernate was too hard to integrate with SFS2X. Hope it helps people out using orm's for their projects !
Yes, it is in the classpath. Classes deployed here are shared across any extension. For more details please check the advanced article on Extension, where it deals with class loading:I was unsure if the __lib__ folder is actually in the class path.
http://docs2x.smartfoxserver.com/Advanc ... extensions