The Publisher table has only one row. When I do a get everything is fine. I can insert and update. I just can't do a query. I am getting this problem with other tables as well. I picked the simplest table to show the problem.
I am using Hybernate Syncronizer to generate the framework.
Hibernate version:3.1.2
Mapping documents:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="name.elliot.bill.pom">
<class
name="Publisher"
table="publisher"
>
<id
name="id"
type="java.lang.Integer"
column="publisherID"
>
<generator class="native"/>
</id>
<property
name="name"
column="name"
type="java.lang.String"
not-null="true"
length="255"
/>
</class>
<query name="library.publisher.byName"><![CDATA[
from Publisher
where name = 'JavaX'
]]></query>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
PublisherDAO daoP = new PublisherDAO();
Integer id;
List results;
Publisher publisher;
Query query;
publisher = daoP.get( new Integer(4) );
if( logger.isInfoEnabled() ) {
if( publisher != null ) {
logger.info("Publisher name = " + publisher.getName() );
} else {
logger.info("Publisher was not found");
}
}
query = daoP.getQuery("from Publisher");
assertNotNull(query);
results = query.list();
Full stack trace of any exception that occurs:Code:
Exception in thread "main" java.lang.NullPointerException
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:442)
at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:368)
at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:105)
at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
at org.hibernate.loader.Loader.doQuery(Loader.java:661)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.doList(Loader.java:2150)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
at org.hibernate.loader.Loader.list(Loader.java:2024)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:369)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:300)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:146)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1093)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
at name.elliot.bill.EntryTest.testEntryDAO(EntryTest.java:62)
at name.elliot.bill.EntryTest.main(EntryTest.java:35)
Name and version of the database you are using:MySQL 4.1 with JConnect version 3.1.12
The generated SQL (show_sql=true):Code:
20:28:17,004 INFO EntryTest:40 - Entered testEntryDAO
ibernate:
select
publisher0_.publisherID as publishe1_1_0_,
publisher0_.name as name1_0_
from
publisher publisher0_
where
publisher0_.publisherID=?
20:28:22,833 INFO EntryTest:55 - Publisher name = JavaX
Hibernate:
select
publisher0_.publisherID as publishe1_1_,
publisher0_.name as name1_
from
publisher publisher0_
Debug level Hibernate log excerpt:
I was not able to get hibernate to output log info. I have log4j jar in class path as well as log4j.properties. But, all I can get to output is my own logging lines. None from hibernate.