gpt4 book ai didi

java - 持久化配置问题

转载 作者:行者123 更新时间:2023-12-01 15:53:35 25 4
gpt4 key购买 nike

我有一个 Web 应用程序(基于 GWT/Vaadin),到目前为止我是通过它启动的

mvn jetty:run

现在我想在另一个 Web 服务器(也是 Jetty)上运行它并遇到数据库连接问题。

WAR 文件中没有 persistence.xml 文件。这会是失败的原因吗?

如果是,我应该如何配置持久性,如果

а) 我正在使用 Java DB (Derby),

b) Hibenate 和

c) 现在配置数据库连接,如下所示

提前致谢

德米特里

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.CURRENT_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:这是异常(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]

最佳答案

异常清楚地表明在类路径中找不到org.apache.derby.jdbc.EmbeddedDriver或其某些依赖项。通常需要将所需的jar文件放入/WEB-INF/lib中(或者在pom.xml中声明,让Maven自动放入)。

关于java - 持久化配置问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5515305/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com