[英]Use hibernate project with EJB
My setup: 我的设置:
ETMEAR: ETMEAR:
When I use library(ETM) from normal Java application it works alright. 当我使用普通Java应用程序中的library(ETM)时,它可以正常工作。
When I try to deploy the whole thing (JBoss 7.1) I get: http://pastebin.com/gDmiFfhL 当我尝试部署整个组件(JBoss 7.1)时,我得到: http : //pastebin.com/gDmiFfhL
I guess what it boils down to is: 我猜可以归结为:
Caused by: org.hibernate.HibernateException: Connection cannot be null
when 'hibernate.dialect' not set
I guess hibernate.cfg.xml is not found. 我猜找不到hibernate.cfg.xml。 Where should I put it?
我应该放在哪里?
I already put a copy in every root of source of every part of application (it's silly but I'm desperate) and it doesn't help. 我已经在应用程序各个部分的源代码的每个根目录中放置了一个副本(虽然很愚蠢,但我很绝望),但它无济于事。
Maybe this is something else? 也许这是另外一回事吗?
Thanks! 谢谢!
Let me know if I can provide more info. 让我知道是否可以提供更多信息。
EDIT: My hibernate.cfg.xml (works for accessing library from Java app): EDIT @ouapdouap : reformated code section 编辑:我的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"/>
I migrated all my config into persistence.xml 我将所有配置迁移到persistence.xml
I put it into: ETMEJB/ejbModule/META-INF/persistence.xml 我将其放入:ETMEJB / ejbModule / META-INF / persistence.xml
So now my ear deploys. 所以现在我的耳朵展开了。
The thing is when I try to use my hibernate objects from EJB it reads persistence.xml not from META-INF of EJB but from META-INF of ETM library, so I have to put the same file in 2 directories: 问题是,当我尝试使用EJB中的休眠对象时,它不是从EJB的META-INF而是从ETM库的META-INF读取persistence.xml,因此我必须将同一文件放在2个目录中:
ETMEJB/ejbModule/META-INF/persistence.xml - so deployment succeeds ETM/src/META-INF/persistence.xml - used when application is running ETMEJB / ejbModule / META-INF / persistence.xml-因此部署成功ETM / src / META-INF / persistence.xml-在应用程序运行时使用
When I first try to use my hibernate object by creating EntityManagerFactory I get following exception: 当我第一次尝试通过创建EntityManagerFactory来使用休眠对象时,出现以下异常:
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.