Hello everybody
I have a problem storing my objects with Hibernate. The following code is part
of a EJB Session Bean and is called by a JSP:
| public String getEchoString(String clientString) {
|
| InitialContext ctx;
| try {
| ctx = new InitialContext();
|
| SessionFactory factory;
| factory = (SessionFactory)
ctx.lookup("java:/hibernate/SessionFactory");
| Session hsession = factory.openSession();
| Transaction tx = hsession.beginTransaction();
|
| Entry newEntry = new Entry();
| newEntry.setEntry(clientString);
| newEntry.setEntrydate(new java.util.Date());
|
| hsession.save(newEntry);
| //hsession.flush();
| tx.commit();
| hsession.close();
| } catch (NamingException e) {
| e.printStackTrace();
| }
| return clientString + " - from session bean";
| }
|
The problem is, that without having a hsession.flush() the object gets not
stored in the database. Can somebody tell me why? Shouldn't a tx.commit() oder
a hsession.close() be enough?
I also have tried the HibernateContext.getSession() version, but I had the same
result. Furthermore Eclipse told me that HibernateContext.getSession()
deprecated. Is this true? What is the best method to get a Hibernate session?
I use JBoss 4.0.3 SP1, Oracle 10.1.0.3 and Hibernate 3.
Thank you,
Marco
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3910028#3910028
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3910028
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user