我的设置:
ETMEAR:
当我使用普通Java应用程序中的库(ETM)时,它可以正常工作。
当我尝试部署整个东西(JBoss 7.1)时,我得到: http://pastebin.com/gDmiFfhL
我想它归结为:
Caused by: org.hibernate.HibernateException: Connection cannot be null
when 'hibernate.dialect' not set
我猜是找不到hibernate.cfg.xml。我应该把它放在哪里?
我已经在应用程序的每个部分的源代码中添加了一个副本(它很愚蠢,但我很绝望)并且它没有帮助。
也许这是别的什么?
谢谢!
如果我能提供更多信息,请告诉我。
编辑:我的hibernate.cfg.xml(适用于从Java应用程序访问库): 编辑@ouapdouap:重新格式化代码部分
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- We're using MySQL database so the dialect needs to MySQL as well-->
<property name="hibernate.dialect">org.hibernate.dialect.HSQLDialect</property>
<!-- Database connection settings -->
<property name="connection.driver_class">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:/data/Documents/etm</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- Disable the second-level cache -->
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<!-- This will drop our existing database and re-create a new one.
Existing data will be deleted! -->
<property name="hbm2ddl.auto">create</property>
<!-- Echo all executed SQL to stdout -->
<property name="show_sql">true</property>
<!-- Names the annotated entity class -->
<mapping class="com.leonty.etm.domain.Contract"/>
<mapping class="com.leonty.etm.domain.Employee"/>
<mapping class="com.leonty.etm.domain.Job"/>
<mapping class="com.leonty.etm.domain.Time"/>
答案 0 :(得分:0)
我将所有配置迁移到persistence.xml
我把它放入: ETMEJB /的ejbModule / META-INF / persistence.xml中
所以现在我的耳朵部署了。
当我尝试使用来自EJB的hibernate对象时,它不是从EJB的META-INF而是从ETM库的META-INF读取persistence.xml,所以我必须将相同的文件放在2个目录中:< / p>
ETMEJB / ejbModule / META-INF / persistence.xml - 因此部署成功 ETM / src / META-INF / persistence.xml - 在应用程序运行时使用
当我第一次尝试通过创建EntityManagerFactory来使用我的hibernate对象时,我得到以下异常:
20:50:47,905 ERROR [SchemaExport] schema export unsuccessful
java.sql.SQLException: You cannot set autocommit during a managed transaction!
at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.setJdbcAutoCommit(BaseWrapperManagedConnection.java:582)