Accessing database from GameManager

27 views
Skip to first unread message

Dennis Hartrampf

unread,
Aug 13, 2011, 7:27:50 AM8/13/11
to Game Gardens
Hi all,

I'm trying to access a mysql database from my GameManager.
My first attempt was to use JPA and Hibernate. I want to migrate code
from a Web application that I developed earlier to a game using game
gardens. In that web app I used JPA and Hibernate. For JPA to work a
persistence.xml file must be in a META-INF folder in the source
directory. But when I start the toybox server from the console (via >
ant dist server), I get an exception that no persistence provider was
found, which means that the persistence.xml was not found.
I modified the game-incl.xml (ant file) so it creates the META-INF
folder in the dist-jar and copies the persistence.xml to it.

Question relating this problem: Does anybody know where I need to put
the persistence.xml so it can be found by the toybox server?

My second attempt was to use a StaticConnectionProvider from
samskivert lib. For this to work there needs to be a properties-file
containing the database parameters (like user, password etc.). And in
that file I specify which connection driver should be used. In my case
that's com.mysql.jdbc.Driver. This file (I put in the META-INF dir) is
found, as the server tries to load the mysql driver. But then get a
ClassNotFoundException pointing out that the driver class was not
found, allthough I have the mysql connector jar on the classpath.

The question here is: Has anybody done that with success before? Can
you tell me, where I need to put the mysql connector so that the
toybox server can find it?

If you can answer one of my questions you will be of great help!

Thanks for any responses!

Michael Bayne

unread,
Aug 16, 2011, 12:24:24 PM8/16/11
to game-g...@googlegroups.com
On Sat, Aug 13, 2011 at 4:27 AM, Dennis Hartrampf <denn...@gmail.com> wrote:
> I'm trying to access a mysql database from my GameManager.
> My first attempt was to use JPA and Hibernate. I want to migrate code
> from a Web application that I developed earlier to a game using game
> gardens. In that web app I used JPA and Hibernate.

Before digging further into this, I should point out that it will not
be possible for you to host your game on the gamegardens.com server if
it uses Hibernate. We don't provide a database for use by games.

So that means you would be running your own ToyBox server on your own
machine, and replicating the entirety of the gamegardens.com setup on
your own hardware. That's no small task, and would probably not be the
right approach if you just wanted to host a single game of your own
authoring, because you don't need all the additional machinery for
allowing other people to upload games and whatnot.

If you do plan to host your own game on your own hardware and want to
set up a simpler standalone server that would allow players to connect
to a lobby (like in Game Gardens) but which only supported your game,
I can point you in the right direction. But if your plan was to upload
your game to gamegardens.com, then I'm afraid you'll have to make do
without a database.

-- m...@samskivert.com

Dennis Hartrampf

unread,
Aug 16, 2011, 3:29:33 PM8/16/11
to Game Gardens
Thanks for your reply!

On Aug 16, 6:24 pm, Michael Bayne <m...@samskivert.com> wrote:
> Before digging further into this, I should point out that it will not
> be possible for you to host your game on the gamegardens.com server if
> it uses Hibernate. We don't provide a database for use by games.

I am indeed planning to host the game on my own machine and not on
gamegardens. It will be part of my master's thesis and I need to have
access to all kind of data collected while playing.

> If you do plan to host your own game on your own hardware and want to
> set up a simpler standalone server that would allow players to connect
> to a lobby (like in Game Gardens) but which only supported your game,
> I can point you in the right direction.

That sounds really good! The lobby part isn't even necessary, the
match making should be by random choosing players for a game and not
by user's choice. So I'm glad i don't have to replicate the whole
gamegardens setup.

Michael Bayne

unread,
Aug 18, 2011, 6:30:55 PM8/18/11
to game-g...@googlegroups.com
On Tue, Aug 16, 2011 at 12:29 PM, Dennis Hartrampf <denn...@gmail.com> wrote:
> That sounds really good! The lobby part isn't even necessary, the
> match making should be by random choosing players for a game and not
> by user's choice. So I'm glad i don't have to replicate the whole
> gamegardens setup.

I took the liberty of creating a totally standalone project that runs
the Reversi sample game in a simple client and server. The code is
here:

https://github.com/samskivert/reversi

It doesn't do any actual matchmaking, other than take the first two
people who log on and stick them in a game. But all of the necessary
pieces should be in place for you to replace Reversi with your game,
and do whatever more complex match making you need. You can also use
the Micasa lobby services in Vilya if you need a proper lobby.

Because this is all standalone, the class loader situation is much
more straightforward than in Game Gardens where we have to put games
in a sandbox and make it possible to unload their class loaders when
they become idle. So you should be able to wire up Hibernate in your
server without any problems.

Good luck with your masters thesis! :)

Michael

-- m...@samskivert.com

Michael Bayne

unread,
Aug 18, 2011, 6:32:51 PM8/18/11
to game-g...@googlegroups.com
On Thu, Aug 18, 2011 at 3:30 PM, Michael Bayne <m...@samskivert.com> wrote:
> I took the liberty of creating a totally standalone project that runs
> the Reversi sample game in a simple client and server.

One thing I didn't wire up is a way to deploy this game as a Java Web
Start app or as an applet. Both should be possible, you'll just need
to put all of the relevant jar files in a directory and create a .jnlp
file, or do something similar for an applet.

Presently, you can simply test the client and server via the Ant
targets, as you would when developing a Game Gardens game.

-- m...@samskivert.com

Dennis Hartrampf

unread,
Aug 19, 2011, 4:30:27 AM8/19/11
to Game Gardens
On Aug 19, 12:30 am, Michael Bayne <m...@samskivert.com> wrote:
> I took the liberty of creating a totally standalone project that runs
> the Reversi sample game in a simple client and server

Wow, great! You are awesome! I didn't expect you to do all of my work
for me ;) But I'm very grateful you did. Thanks alot.
Now I am very eager to throw my code into your's and see everything
running.
Reply all
Reply to author
Forward
0 new messages