Hibernate Books

All times are UTC - 5 hours [ DST ]

Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: weird HQL problem:select query doesn't retrieve the Id field
PostPosted: Thu Nov 18, 2010 5:52 am 

Joined: Thu Nov 18, 2010 5:37 am
Posts: 2
hi all,
I'm using Hibernate 3.2 along with Spring 2.5 and MySql 5.In my DAOs I use Spring's HibernateTemplate.find() method with query string "from Messages where lang="+"'"+lang+"'" and I've noticed that in all Messages POJOs returned from the query the id field is set with its default value (zero,that is).But when I use the query "select id from Messages" the ids in the list returned are correct.Is there a solution to that problem?
here is the Messages.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
  <class name="gr.nikoslianeris.model.Messages" table="messages">
    <id column="id" type="long" access="field">
      <generator  class="native"/>
    <property column="mesname" name="mesname" type="string"/>
    <property column="message" name="message" type="string"/>
    <property column="lang" name="lang" type="string"/>

the hibernate.cfg.xml
<?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">
    <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
    <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/lianeris</property>
    <property name="hibernate.connection.username">root</property>
    <property name="hibernate.show_sql">true</property>
    <property name="hibernate.format_sql">true</property>
    <mapping resource="gr/nikoslianeris/model/Messages.hbm.xml"/>
    <mapping resource="gr/nikoslianeris/model/News.hbm.xml"/>
    <mapping resource="gr/nikoslianeris/model/Portfolio.hbm.xml"/>
    <mapping resource="gr/nikoslianeris/model/Articles.hbm.xml"/>

thank in advance for your time

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

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.