Hi,
I've got a problem trying to read entries out of my database when I'm providing a value for the primary key.
For example, the following works fine:
Code:
Customer c1 = (Customer) session.createQuery("FROM Customer c WHERE c.firstName = ?").setString(0, "Test").uniqueResult();
But when I use one of the following:
Code:
Customer c1 = (Customer) session.createQuery("FROM Customer c WHERE c.customerId = ?").setInteger(0, 1).uniqueResult();
or
Code:
Object testCustomer = session.get(Customer.class, 1);
I just get a null object.
Interestingly, when I fetch a customer by it's name (which works fine), and print out the id afterwards, it matches the value I provide
when trying to fetch the customer by id (in this case 1).
Here's my hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="show_sql">true</property>
<property name="format_sql">true</property>
<property name="dialect">dialect.SQLiteDialect</property>
<property name="connection.driver_class">org.sqlite.JDBC</property>
<property name="connection.url">jdbc:sqlite:aic.db</property>
<property name="connection.username"></property>
<property name="connection.password"></property>
<property name="hbm2ddl.auto">create</property>
<mapping resource="Customer.hbm.xml"/>
<!-- I removed the other mapping resources to keep this short -->
</session-factory>
</hibernate-configuration>
And my Customer.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Oct 18, 2011 5:39:40 PM by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping>
<class name="at.ac.tuwien.infosys.aic11.dto.Customer" table="CUSTOMER">
<id name="customerId" type="long">
<column name="CUSTOMERID" />
<generator class="increment" />
</id>
<property name="firstName" type="java.lang.String">
<column name="FIRSTNAME" />
</property>
<property name="middleName" type="java.lang.String">
<column name="MIDDLENAME" />
</property>
<property name="lastName" type="java.lang.String">
<column name="LASTNAME" />
</property>
<property name="openBalance" type="long">
<column name="OPENBALANCE" />
</property>
<!-- I removed the relationships to other entities to keep this short -->
</class>
</hibernate-mapping>
Any suggestions what I need to do?
Alex