开发者

Persistence configuration question

开发者 https://www.devze.com 2023-02-21 23:45 出处:网络
I have a web application (GWT/Vaadin based), which up to now I launched via mvn jetty:run Now I want to run it on another web server (also Jetty) and get database connection problems.

I have a web application (GWT/Vaadin based), which up to now I launched via

mvn jetty:run

Now I want to run it on another web server (also Jetty) and get database connection problems.

In the WAR file there is no persistence.xml file. Can this be the reason for the failure?

If yes, how should I configure the persistence, if

а) I'm using Java DB (Derby),

b) Hibenate and

c) now configure the DB connection like shown below

?

Thanks in advance

Dmitri

private void tryToOpenSession(final String aConnectionString)
        throws Throwable {
    ...

    state = PersistenceState.OPENING_CONNECTION;
    final Configuration cnf = new Configuration();
    cnf.setProperty(Environment.DRIVER,
            "org.apache.derby.jdbc.EmbeddedDriver");
    cnf.setProperty(Environment.URL, aConnectionString);
    cnf.setProperty(Environment.DIALECT, DerbyDialect.class.getName());
    cnf.setProperty(Environment.SHOW_SQL, "true");
    cnf.setProperty(Environment.HBM2DDL_AUTO, "update");
    cnf.setProperty(Environment.CURRE开发者_JAVA百科NT_SESSION_CONTEXT_CLASS, "thread");

    cnf.addResource("persistence/Entity1.hbm.xml");
    cnf.addResource("persistence/Entity2.hbm.xml");
    ...
    cnf.addResource("persistence/EntityN.hbm.xml");

    sessionFactory = cnf.buildSessionFactory();

    session = getSession();

    ...

    state = PersistenceState.CONNECTION_OPEN;
}

UPD: Here's the exception:

java.lang.NoClassDefFoundError: Could not initialize class org.apache.derby.jdbc.EmbeddedDriver
    at java.lang.Class.forName0(Native Method) ~[na:1.6.0_20]
    at java.lang.Class.forName(Class.java:186) ~[na:1.6.0_20]
    at org.hibernate.connection.DriverManagerConnectionProvider.configure(DriverManagerConnectionProvider.java:80) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:143) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:459) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840) ~[hibernate-core-3.6.0.Final.jar:3.6.0.Final]


Exception clearly says that org.apache.derby.jdbc.EmbeddedDriver or some of its dependencies can't be found in the classpath. Usually you need to put required jar files into /WEB-INF/lib (or declare them in pom.xml to make Maven put them automatically).

0

精彩评论

暂无评论...
验证码 换一张
取 消