-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: getResultList returns empty list [SOLVED]
PostPosted: Wed Dec 26, 2012 12:50 pm 
Newbie

Joined: Fri Feb 15, 2008 11:21 am
Posts: 3
Hello *,

I'm trying to use Hibernate 4.1.9-Final as JPA 2 provider, injected by Guice in a Wicket application. I face two problems that may be related to each other, but I'm not sure.

The 1st is that, on application start, I get in my Tomcat 7.0.34 logs the following:

javax.naming.NameNotFoundException: Name [jdbc/mercatinoDatabase] is not bound in this Context. Unable to find [jdbc].

The second problem is that getResultList returns an empty list after a query I'm sure should return 20 rows.

Now it could seem obvious I should fix the 1st problem before moving to the next, but I suspect that exception is actually inoffensive, because I've already seen the app retrieving at least the 1st row yesterday, and that exception has always been there. After my app retrieved the 1st row, it threw an exception due to a different bug I've now patched, but after that run when it returned the 1st row, it stopped retrieving rows and hibernate started giving me always empty result lists. I've altready tried restarting tomcat with no luck.

Here is my WEB-INF/web.xml snippet:

Code:

   <resource-ref>
    <description>
       reference to db connection in context.xml
    </description>
    <res-ref-name>
      jdbc/mercatinoDatabase
    </res-ref-name>
    <res-type>
      javax.sql.DataSource
    </res-type>
    <res-auth>
      Container
    </res-auth>
  </resource-ref>


My full META-INF/context.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/SalixWeb">
  <Resource auth="Container" driverClassName="com.mysql.jdbc.Driver" maxActive="8" maxIdle="4"
   name="jdbc/mercatinoDatabase" password="secret" type="javax.sql.DataSource"
   url="jdbc:mysql://localhost:4306/mydb_dev?zeroDateTimeBehavior=convertToNull&amp;autoReconnect=true"
   username="root"/>
</Context>


My WEB-INF/classes/META-INF/persistence.xml

Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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_2_0.xsd">
  <persistence-unit name="mercatino-unit" transaction-type="RESOURCE_LOCAL">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <non-jta-data-source>java:comp/env/jdbc/mercatinoDatabase</non-jta-data-source>
    <properties>
      <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
      <property name="hibernate.archive.autodetection" value="class, hbm"/>
      <property name="hibernate.show_sql" value="true"/>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
      <property name="hibernate.c3p0.min_size" value="5"/>
      <property name="hibernate.c3p0.max_size" value="20"/>
      <property name="hibernate.c3p0.timeout" value="300"/>
      <property name="hibernate.c3p0.max_statements" value="50"/>
      <property name="hibernate.c3p0.idle_test_period" value="3000"/>
    </properties>
  </persistence-unit>
</persistence>


And, finally, my code snippet:

Code:
    CriteriaBuilder cb = em.getCriteriaBuilder();
    CriteriaQuery<JosUsers> cq = cb.createQuery(JosUsers.class);
    Root<JosUsers> ru = cq.from(JosUsers.class);
    cq.select(ru);
    cq.orderBy(cb.asc(ru.get("id")));
    Query q = em.createQuery(cq);
    List<JosUsers> lresults = q.getResultList(); // always lresults.size() == 0 !!!
    for (JosUsers user: lresults)
    {
      System.err.println(user.getName());
    }


Any hints?

_________________
Virtual Bit di Lucio Crusca
http://www.virtual-bit.com


Last edited by Lucrus on Wed Dec 26, 2012 8:33 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: getResultList returns empty list [SOLVED]
PostPosted: Wed Dec 26, 2012 8:31 pm 
Newbie

Joined: Fri Feb 15, 2008 11:21 am
Posts: 3
Problem 1: solved by commenting out the <resource-ref> in web.xml (not sure what it was useful for indeed, but copied and pasted from somewhere)

Problem 2: persistence.xml said <property name="hibernate.hbm2ddl.auto" value="create-drop"/>, which basically dropped my database after the 1st successful debug session. It's normal to find it empty after that...

_________________
Virtual Bit di Lucio Crusca
http://www.virtual-bit.com


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.