You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomee.apache.org by emaborsa <in...@emaborsa.com> on 2013/09/28 17:23:57 UTC

No results from query on postgres

It's the first time i work with TomEE and Hibernate. I configures my
persistence.xml and hibernate.cfg.xml. 
I built a webApp using EJB3 with @Stateless bean and a 
@PersistenceContext(name = "persistentUnitJndi", unitName = "docTracingPU").
The docTracingPU is defined in the persistence.xml and instantiated
correctly be TomEE. 
The problem is when i create a Query and call getResultList()....it always
returns an empty list. IF i write the same query in PGAdmin i get results...

I guess i have to configure TomEE with some parameters, but i don't
understand how/what.



--
View this message in context: http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: No results from query on postgres

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Whats pgadmin?

Was your datasource adjusted (printed in logs)
Le 28 sept. 2013 18:16, "emaborsa" <in...@emaborsa.com> a écrit :

> It's the first time i work with TomEE and Hibernate. I configures my
> persistence.xml and hibernate.cfg.xml.
> I built a webApp using EJB3 with @Stateless bean and a
> @PersistenceContext(name = "persistentUnitJndi", unitName =
> "docTracingPU").
> The docTracingPU is defined in the persistence.xml and instantiated
> correctly be TomEE.
> The problem is when i create a Query and call getResultList()....it always
> returns an empty list. IF i write the same query in PGAdmin i get
> results...
>
> I guess i have to configure TomEE with some parameters, but i don't
> understand how/what.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: No results from query on postgres

Posted by Romain Manni-Bucau <rm...@gmail.com>.
Hi

Yes we often use default datasource for our samples.

Btw we have a property to fail instead of using defaults when a resource is
missing, can help you to find it maybe
Le 29 sept. 2013 13:58, "emaborsa" <in...@emaborsa.com> a écrit :

> ...i removed the hibernate.cfg.xml, added the resource in the tomEE.xml and
> it WORKS!
>
> The point is that the most examples i've found doesn't show the tomee.xml
> config.
>
> However,
> Thants a lot!
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665353.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: No results from query on postgres

Posted by emaborsa <in...@emaborsa.com>.
...i removed the hibernate.cfg.xml, added the resource in the tomEE.xml and
it WORKS!

The point is that the most examples i've found doesn't show the tomee.xml
config.

However,
Thants a lot!



--
View this message in context: http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665353.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: No results from query on postgres

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Exactly. duplicate this one with jtamanaged to true. Then just remove the
hibernate xml file as you don't need it for the moment. And give the same
datasource Id to both jta-datasource and non-jta-datasource
Le 28 sept. 2013 19:13, "emaborsa" <in...@emaborsa.com> a écrit :

> sorry, i forgot the TomEE.xml:
>
> <tomee>
>      <Resource id="docTracingPU" type="DataSource">
>           JdbcDriver org.postgresql.Driver
>           JdbcUrl jdbc:postgresql://127.0.0.1:5433/doctracing
>           UserName emaborsa
>           Password eqb9cnu1
>           JtaManaged false
>     </Resource>
> </tomee>
>
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665343.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: No results from query on postgres

Posted by emaborsa <in...@emaborsa.com>.
sorry, i forgot the TomEE.xml:

<tomee>
     <Resource id="docTracingPU" type="DataSource">
          JdbcDriver org.postgresql.Driver
          JdbcUrl jdbc:postgresql://127.0.0.1:5433/doctracing
          UserName emaborsa
          Password eqb9cnu1
          JtaManaged false
    </Resource>
</tomee>




--
View this message in context: http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665343.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: No results from query on postgres

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
OK then, You need instead of configuring your datasource in the hibernate
xml file, you need to add a jta data source in the persistence.xml file and
create a data source in conf/tomee.xml with the same name. Checkout the
large number of examples. That should work easily.
Le 28 sept. 2013 19:09, "emaborsa" <in...@emaborsa.com> a écrit :

> My persistence.xml:
>
> <persistence-unit name="docTracingPU" transaction-type="JTA">
>         <provider>org.hibernate.ejb.HibernatePersistence</provider>
>
> <non-jta-data-source>java:comp/env/jdbc/docTracing</non-jta-data-source>
>
>
> <class>com.emaborsa.doctracing.core.persistentobject.UtentePO</class>
>
> <class>com.emaborsa.doctracing.core.persistentobject.CartellaPO</class>
>
>
> <class>com.emaborsa.doctracing.core.persistentobject.AutorizzazionePO</class>
>
>
> <class>com.emaborsa.doctracing.core.persistentobject.StoricoUtilizzoCartellaPO</class>
>         <properties>
>                 <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect"/>
>                 <property name="hibernate.hbm2ddl.auto" value="update" />
>                 <property name="hibernate.transaction.manager_lookup_class"
> value="org.apache.openejb.hibernate.TransactionManagerLookup" />
>
>                 <property name="format_sql" value="true" />
>                 <property name="hibernate.show_sql" value="true" />
>                 <property name="use_sql_comments" value="true"/>
>         </properties>
> </persistence-unit>
>
> My hibernate.cfg.xml:
>
> <session-factory>
>         <property
> name="connection.url">jdbc:postgresql://127.0.0.1:5432/mydb</property>
>         <property
> name="connection.driver_class">org.postgresql.Driver</property>
>         <property name="connection.username">myuser</property>
>         <property name="connection.password">mypass</property>
>         <property
>
> name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
>         <property
> name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
>         <property
>
> name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
> </session-factory>
>
> I have not configured anything else...
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665342.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>

Re: No results from query on postgres

Posted by emaborsa <in...@emaborsa.com>.
My persistence.xml:

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

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

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

<class>com.emaborsa.doctracing.core.persistentobject.StoricoUtilizzoCartellaPO</class>
	<properties>
		<property name="hibernate.dialect"
value="org.hibernate.dialect.PostgreSQLDialect"/>
		<property name="hibernate.hbm2ddl.auto" value="update" />
		<property name="hibernate.transaction.manager_lookup_class"
value="org.apache.openejb.hibernate.TransactionManagerLookup" />
			
		<property name="format_sql" value="true" />
		<property name="hibernate.show_sql" value="true" />
		<property name="use_sql_comments" value="true"/> 
	</properties>
</persistence-unit>

My hibernate.cfg.xml:

<session-factory>
	<property
name="connection.url">jdbc:postgresql://127.0.0.1:5432/mydb</property>
	<property name="connection.driver_class">org.postgresql.Driver</property>
	<property name="connection.username">myuser</property>
	<property name="connection.password">mypass</property>
	<property
name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
	<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
	<property
name="cache.provider_class">org.hibernate.cache.HashtableCacheProvider</property>
</session-factory>

I have not configured anything else...



--
View this message in context: http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339p4665342.html
Sent from the OpenEJB User mailing list archive at Nabble.com.

Re: No results from query on postgres

Posted by Jean-Louis MONTEIRO <je...@gmail.com>.
Posgres admin Romain I guess.
Could you provide us with logs?
Tomee is probably adjusting your data source to an hsql if you did not
configured it in tomee.XML
Le 28 sept. 2013 18:16, "emaborsa" <in...@emaborsa.com> a écrit :

> It's the first time i work with TomEE and Hibernate. I configures my
> persistence.xml and hibernate.cfg.xml.
> I built a webApp using EJB3 with @Stateless bean and a
> @PersistenceContext(name = "persistentUnitJndi", unitName =
> "docTracingPU").
> The docTracingPU is defined in the persistence.xml and instantiated
> correctly be TomEE.
> The problem is when i create a Query and call getResultList()....it always
> returns an empty list. IF i write the same query in PGAdmin i get
> results...
>
> I guess i have to configure TomEE with some parameters, but i don't
> understand how/what.
>
>
>
> --
> View this message in context:
> http://openejb.979440.n4.nabble.com/No-results-from-query-on-postgres-tp4665339.html
> Sent from the OpenEJB User mailing list archive at Nabble.com.
>