-->
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: Can't select when providing an id value
PostPosted: Wed Oct 26, 2011 10:40 am 
Newbie

Joined: Wed Oct 26, 2011 10:34 am
Posts: 2
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


Top
 Profile  
 
 Post subject: Re: Can't select when providing an id value
PostPosted: Wed Oct 26, 2011 11:29 am 
Newbie

Joined: Wed Oct 26, 2011 10:34 am
Posts: 2
Seems to be resolved, using .setLong() instead of .setInteger() obviously worked.

My bad ;/

Alex


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.