Tomber上的Postgres的Hibernate问题

时间:2013-09-27 12:48:14

标签: hibernate java-ee postgresql-9.2 tomee

我正在使用在TomEE上运行的Java编写的WebApp。作为持久层,我使用Hibernate。已配置Persistence.xml,实体管理器由TomEE在 @PersistenceContext(name = "persistentUnitJndi", unitName = "docTracingPU") EJB中使用 @Stateless(name = "utenteFacade", mappedName = IUtente.MAPPED_NAME)实例化。

它似乎工作正常,但所有查询都返回一个空结果(空列表)。 DB是PostrgeSQL,我试过8.4和9.2但结果总是一样。

我在postrges(postgresql.conf)上登录,我只读Could not receive data from client: Unknown winsock error 10061

我尝试关闭防病毒软件和/或防火墙....没有任何变化。

怎么办?

编辑:

我在Win8.1机器上尝试过相同的项目。我得到user lacks privilege or object not found

1 个答案:

答案 0 :(得分:0)

我找到了:

  • hibernate.cfg.xml不是neede
  • 仅需要persistence.xml和tomee.xml

我举了我的例子:

<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
   http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">

<persistence-unit name="docTracingPU" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:comp/env/jdbc/docTracing</jta-data-source>
    <non-jta-data-source>java:comp/env/jdbc/docTracing</non-jta-data-source>

    <class>com.emaborsa.doctracing.core.persistentobject.UtentePO</class>

    <properties>
        <property name="hibernate.hbm2ddl.auto" value="validate" />
         <property name="hibernate.transaction.flush_before_completion" value="true"/>
         <property name="hibernate.transaction.auto_close_session" value="true"/>
        <property name="hibernate.transaction.manager_lookup_class" value="org.apache.openejb.hibernate.TransactionManagerLookup" />
         <property name="hibernate.transaction.flush_before_completion" value="true"/>
         <property name="hibernate.transaction.auto_close_session" value="true"/>

        <!-- Print SQL to stdout. -->
        <property name="hibernate.show_sql" value="true" />
        <property name="hibernate.format_sql" value="true" />
    </properties>
</persistence-unit>

 <?xml version="1.0" encoding="UTF-8"?> 
     <tomee> 
        <Resource  id="docTracingPU" type="DataSource">
           JdbcDriver org.postgresql.Driver
           JdbcUrl jdbc:postgresql://127.0.0.1:5432/myDb
           UserName ****
           Password ****
           JtaManaged false
          TestWhileIdle true
          InitialSize 5
          </Resource> 
        <Resource id="docTracingPU" type="DataSource">
           JdbcDriver org.postgresql.Driver
           JdbcUrl jdbc:postgresql://127.0.0.1:5432/myDb
           UserName *****
           Password *****
           JtaManaged true
          TestWhileIdle true
          InitialSize 5
     </Resource> 
 </tomee>