hallo,
ich bin noch recht unerfahren mit der materie...
...trotzdem habe ich den zugriff auf javaclassen via java_rpc hinbekommen.
ich kann also daten senden und ergebnisse empfangen.
jetzt möchte ich vi java_rpc und hibernate auf eine datenbank zugreifen.
als standalone anwendung (java + hibernate) kein problem.
aber
- mit openlaszlo (+tomcat) bekomme ich aber immer nur eine fehlermeldung (timed out) beim aufruf meiner funktionen über das debug-fenster...
- die datenbankfunktionen laufen nicht durch.
weiß jemand rat?
ich vermute mal das sessionhandling ist falsch implementiert....?
...ein lama für ein beispiel....
das lzx-file
Code:
...
<security>
<allow>
<pattern>^zumtest\.Test</pattern>
</allow>
</security>
<javarpc name="test_rpc" scope="session" autoload="true" remoteclassname="zumtest.Test">
<handler name="onerror" args="err">
Debug.write(err);
</handler>
<handler name="onload">
</handler>
</javarpc>
...
<button align="center" name="saveCode_btn" text="Speichern">
// java aufrufen
<handler name="onclick">
this.setTest.invoke();
</handler>
<remotecall funcname="setTest" remotecontext="$once{canvas.test_rpc}">
</remotecall>
// rueckgabewert uebernehmen
<handler name="ondata" args="res">
parent.code_input.setAttribute("text",res);
</handler>
</button>
...
die testklasse
Code:
package zumtest;
import java.util.Date;
import zumtest.dbroutines.*;
public class Test {
// das klappt super
public String getInfo(String s) {
String ss = new String ("123456789");
if (s.equalsIgnoreCase(ss)) {
ss = "true";
} else {
ss = "false";
}
return ss;
}
public String setTest () {
DBtest _pc = new DBtest();
String _result = _pc.newEintrag(new Date(), new Date(),"1234567","12345667");
return _result;
}
}
Code:
package zumtest.dbroutines;
import java.util.Date;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.HibernateException;
import org.hibernate.ce.auction.sessions.*;
import zumtest.tables.tabelle1.*;
public class DBtest {
// portalcode anlegen
public String newEintrag (Date start, Date stop, String code, String application) {
TBLtablle1 _pc = new TBLtabelle1(); // klappt
_pc.setId(0); // klappt
_pc.setStart(start); // klappt
_pc.setStop(stop); // klappt
_pc.setCode(code); // klappt
_pc.setApplication(application); // klappt
// das liebe datenbankhandling
Session _session = null; // klappt
Transaction transaction = null; // klappt
// ab hier wirds eigenartig
try {
_session = HibernateSession.getSession();
transaction = _session.beginTransaction();
_session.save(_pc);
transaction.commit();
}
catch (HibernateException e) {
if (transaction != null) {
transaction.rollback();
throw e;
}
}
finally {
HibernateSession.closeSession();
}
return String.valueOf(_pc.getId());
}
...
}
... auszug aus dem logging
Quote:
798536 [http-8080-Processor22] DEBUG org.hibernate.impl.SessionImpl 127.0.0.1 12 - opened session at timestamp: 12374793343
798536 [http-8080-Processor22] DEBUG org.hibernate.transaction.JDBCTransaction 127.0.0.1 12 - begin
798536 [http-8080-Processor22] DEBUG org.hibernate.jdbc.ConnectionManager 127.0.0.1 12 - opening JDBC connection
798536 [http-8080-Processor22] DEBUG org.hibernate.transaction.JDBCTransaction 127.0.0.1 12 - current autocommit status: false
798536 [http-8080-Processor22] DEBUG org.hibernate.event.def.AbstractSaveEventListener 127.0.0.1 12 - executing identity-insert immediately
798536 [http-8080-Processor22] DEBUG org.hibernate.jdbc.AbstractBatcher 127.0.0.1 12 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
798537 [http-8080-Processor22] DEBUG org.hibernate.SQL 127.0.0.1 12 -
insert
into
tabelle1
(id, start, stop, code, application)
values
(null, ?, ?, ?, ?)
Hibernate:
insert
into
tabelle1
(id, start, stop, code, application)
values
(null, ?, ?, ?, ?)
798537 [http-8080-Processor22] DEBUG org.hibernate.jdbc.AbstractBatcher 127.0.0.1 12 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
798537 [http-8080-Processor22] DEBUG org.hibernate.jdbc.AbstractBatcher 127.0.0.1 12 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
798537 [http-8080-Processor22] DEBUG org.hibernate.SQL 127.0.0.1 12 -
call identity()
Hibernate:
call identity()
798537 [http-8080-Processor22] DEBUG org.hibernate.id.IdentifierGeneratorFactory 127.0.0.1 12 - Natively generated identity: 19
798537 [http-8080-Processor22] DEBUG org.hibernate.jdbc.AbstractBatcher 127.0.0.1 12 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
798538 [http-8080-Processor22] DEBUG org.hibernate.transaction.JDBCTransaction 127.0.0.1 12 - commit
798538 [http-8080-Processor22] DEBUG org.hibernate.event.def.AbstractFlushingEventListener 127.0.0.1 12 - processing flush-time cascades
798538 [http-8080-Processor22] DEBUG org.hibernate.event.def.AbstractFlushingEventListener 127.0.0.1 12 - dirty checking collections
798538 [http-8080-Processor22] DEBUG org.hibernate.transaction.JDBCTransaction 127.0.0.1 12 - rollback
798538 [http-8080-Processor22] DEBUG org.hibernate.transaction.JDBCTransaction 127.0.0.1 12 - rolled back JDBC Connection
798538 [http-8080-Processor22] DEBUG org.hibernate.jdbc.ConnectionManager 127.0.0.1 12 - aggressively releasing JDBC connection
798538 [http-8080-Processor22] DEBUG org.hibernate.jdbc.ConnectionManager 127.0.0.1 12 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
...meine hibernate-session gekomme ich über
Code:
package org.hibernate.ce.auction.sessions;
import org.hibernate.*;
import org.hibernate.Session;
import org.hibernate.cfg.Configuration;
public class HibernateSession {
private static SessionFactory sessionFactory;
public static final ThreadLocal session = new ThreadLocal();
public static Session getSession()
throws HibernateException {
Session s = (Session) session.get();
if (s == null) {
// Don't get from JNDI, use a static SessionFactory
if (sessionFactory == null) {
// Use default hibernate.cfg.xml
sessionFactory = new Configuration().configure().buildSessionFactory();
}
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession()
throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null) s.close();
}
}
zusätzlich gecheckt:
- listener in web.xml für die sessionfactory klappt.