-->
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: Not retrieving row from database
PostPosted: Mon Aug 15, 2005 7:41 am 
Newbie

Joined: Sat Jul 09, 2005 10:07 pm
Posts: 6
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3.0.5

Mapping documents:<hibernate-mapping>
<class name="bnice.golf.data.Player" table="PLAYER">

<id name="playerId" column="PLAYER_ID" unsaved-value="null">
<generator class="identity"/>
</id>

<property name="username" type="string" column="username" length="16" not-null="true"/>
<property name="password" length="16" column="password" not-null="true"/>
<property name="firstName" column="first_name" length="16" not-null="true"/>
<property name="lastName" column="last_name" length="16" not-null="true"/>
<property name="handicap"/>

<many-to-one name="address" column="address_id" class="Address"/>

</class>
</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
public Player login(final String username, final String password) {
HibernateTemplate template = new HibernateTemplate(this.sessionFactory);
return (Player) template.execute(new HibernateCallback() {
public Object doInHibernate(Session session) throws HibernateException {
Query query = session.createQuery(
"from bnice.golf.data.Player player where player.username=? and password=?");
query.setString(0, username);
query.setString(1, password);
System.out.println("Size:"+query.list().size()+" "+username+" "+password+" "+query.getQueryString());
return query.uniqueResult();
}
});
}


Full stack trace of any exception that occurs:

Name and version of the database you are using:MySQL 4

The generated SQL (show_sql=true):
from bnice.golf.data.Player player where username=? and password=?


Debug level Hibernate log excerpt:

I'm using hibernate with Spring, here is my Spring configuratin:



Code:
   <!-- DATABASE -->
   <bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
      <property name="jndiName">
         <value>java:comp/env/jdbc/myGolf</value>
      </property>
   </bean>
   <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
      <property name="dataSource">
         <ref bean="dataSource"/>
      </property>
      <property name="hibernateProperties">
         <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLInnoDBDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
         </props>
      </property>
      <property name="mappingDirectoryLocations">
         <list>
            <value>classpath:/bnice/golf/data</value>
         </list>
      </property>       
   </bean>       

   <!-- DAO -->
   <bean id="playerDAO" class="bnice.golf.dao.PlayerDAOImpl">
      <property name="sessionFactory">
         <ref bean="sessionFactory"/>
      </property>
   </bean>


When I run this, I get no rows returned from the query, even though there is a row that matches in the database. The println for query.list() always returns "Size: 0". It looks like my database information is set up correctly because I can take out the Hibernate code and put straight JDBC code in and I am able to retrieve the row:

Code:
  DataSource ds = null;

           try {
               try {
                   Context ic = (Context) new InitialContext().lookup("java:comp/env");

                   ds = (DataSource) ic.lookup("jdbc/myGolf");
               } catch (Exception e) {
                   System.out.println("Error getting DS.");
               }

               Connection con = ds.getConnection();
               Statement st = con.createStatement();
               ResultSet rs = st.executeQuery("Select * from player where username='bcnice99' and password='password'");
               if (rs.next()) {
                  System.out.println("Found");
               }
               else {
                  System.out.println("not Found");
               }
               con.close();
           } catch (Exception e) {
               System.out.println("Error getting DataSource");
           }
         return showForm(req, res, errors);


Any ideas why this is not working? I'm new to Hibernate so any help is greatly appreciated!
thanks
Brian


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 15, 2005 9:46 am 
Beginner
Beginner

Joined: Tue Jun 21, 2005 3:15 pm
Posts: 29
Please post your logging out.
Thanks,
B

_________________
Don't forget to rate


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.