Hello,
i am new to hibernate and trying to use it in a simple client server application. i hope i will try to explain well the situation.
1- i have a message class, which contains a client and a session object. , session object contains several session information and an Arraylist of event objects.
2 - Client side is producing an XML string for a message and sending it to server via sockets.
3- Server produces a reader thread for each incoming connection. server takes the XML message in the thread and produces an object from the XML string (using XStream, dont ask why i am converting to XML, is another issue..). Then it produces a persistent version of the message (including persistend versions of session, client id and events in it)
4- then it tries to insert it to the DB (HSQLDB) in the same socket reading thread.
For testing i am sending randomly produced messages sequentally from the client with 150ms intervals. if i send 100 messages, server handles it well but it seems it inserts each message after quite a delay.
When i tried to run two seperate client application, this time, after some time application gives me "Out of memory error".
my insertion code is stg like this (some lines of code is erased for simplification):
Code:
public class Inserter {
Configuration cfg = new Configuration();
public Inserter() throws MappingException {
cfg.addClass(PMessage.class)
.addClass(PSession.class)
.addClass(PClient.class)
.addClass(PEvent.class);
}
.....
public void insertMessage(PMessage m) throws Exception {
// configure hibernate
SessionFactory sf = cfg.buildSessionFactory();
// Open Session
Session sess = sf.openSession();
// start tr, save message and other objects within
Transaction t = sess.beginTransaction();
sess.save(m.getSession());
sess.save(m.getClient());
sess.save(m);
t.commit();
sess.close();
}
}
have i understood the hibernate wrong? or stg wrong with my approach?
i can send some details of mapping files etc if anyone wants.
Thanks for this great software,
Ahmet