-->
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.  [ 1 post ] 
Author Message
 Post subject: hql not returing unique values
PostPosted: Sat Nov 16, 2013 2:17 am 
Newbie

Joined: Fri Nov 15, 2013 7:03 am
Posts: 1
Code:
cfg.file
------------
  <property name="hibernate.bytecode.use_reflection_optimizer">false</property>
  <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
  <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/GuestBook</property>
  <property name="hibernate.connection.username">root</property>
  <property name="hibernate.connection.password">usman</property>
  <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
  <property name="hbm2ddl.auto">update</property>
  <property name="show_sql">true</property>


Code:
hbm.xml
<hibernate-mapping>
<class name="it.rpf.pojo.GuestBook" table="Guestbook" >
    <id name="visitorNo" type="java.lang.Integer">
        <column name="visitorNo" />
        <generator class="identity" />
    </id>
    <property name="visitorName" type="string">
        <column name="visitorName" length="50" />
    </property>
    <property name="message" type="string">
        <column name="message" length="100" />
    </property>
    <property name="messageDate" type="string">
        <column name="messageDate" length="40" />
    </property>
</class>


Code:
SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
    Session session = null;
    try {
        SessionFactory factory = new Configuration().configure().buildSessionFactory();
        session = factory.openSession();

        System.out.println(" session established ");

         List<GuestBook> list = session.createQuery( "from GuestBook" ).list();
         System.out.println( "size>>> "+ list.size());
         for (GuestBook guestBook : list) {
            System.out.println( "---> "+ guestBook.getVisitorName() );
            System.out.println( "---> "+ guestBook.getMessage() );
            System.out.println( "---> "+ guestBook.getMessageDate() );
        }
        System.out.println( "data commited ");
    } catch (HibernateException e) {
        e.printStackTrace();
    } //catch (ParseException e) {
        //e.printStackTrace();
    //}
finally{
          // Actual contact insertion will happen at this step
    /*if (!transaction.wasCommitted()) {
        transaction.rollback();
    }*/

          //session.flush();
          session.close();

          }
}

}


when the test class run it returns only the last record of the dp table. meas if db contain 5 record then test class returns 5 times of last record . help me please

suppose db contain (1) usman,hi,12/11/2013, (2) pavan,hello,2/12/2013,
output is pavan,hello,2/12/2013, pavan,hello,2/12/2013,


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.