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&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?