-->
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: utterly stumped - HQL query stalls program - worth USD50.00
PostPosted: Thu Sep 29, 2011 11:43 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2010 4:32 pm
Posts: 22
Greetings all,

I've used Eclipse to create a Spring/Hibernate standalone desktop GUI app whose behavior has got me buffaloed - it stalls with no error messages when it hits an HQL query statement in a DAO method.

UserDAOHibernate.java
Code:
    package com.ecs.trial_spring.dao.hibernate; 
     
    import org.hibernate.*; 
    import org.springframework.transaction.annotation.Transactional; 
     
    import com.ecs.trial_spring.dao.UserDAO; 
    import com.ecs.trial_spring.model.User; 
     
    import static org.hibernate.criterion.Expression.*; 
     
    import java.util.*; 
     
    import utils.Utils; 
     
    import java.net.*; 
    import java.sql.*; 
     
    @Transactional 
    public class UserDAOHibernate implements UserDAO 
    { 
        private SessionFactory sf; 
         
        public void setSessionFactory(SessionFactory sf) {   // contextual sessions method 
            this.sf = sf; 
        } 
         
     
      @SuppressWarnings("unchecked") 
      public boolean validateIt( String aa, String bb, String cc, String dd) 
      {          //            username   passsword  appname    serialnumber 
        boolean out_bool = false; 
         
        System.out.println("    entering UserDAO.validateIt with:" + aa + ":" + bb + ":" + cc + ":" + dd); 
         
        String sqlcmd_a; 
        String sqlcmd_b; 
        List<User> results_b = null; 
        User result_b = null; 
        String sqlcmd_c; 
        Long id_of_user; 
             
        java.util.Date today = new java.util.Date(); 
     
        sqlcmd_b = " FROM User WHERE userName = :kxa "; 
        System.out.println("    got to A"); 
        Query hqlQuery_b = sf.getCurrentSession().createQuery( sqlcmd_b);  // <-- this line causes stall 
        System.out.println("    got to B"); 
        hqlQuery_b.setParameter( "kxa", aa); 
        System.out.println("    got to C"); 
        results_b = hqlQuery_b.list(); 
        System.out.println("    got to D"); 
        if( results_b.size() == 1) { 
            System.out.println("    got to E"); 
            result_b = results_b.get(0); 
            System.out.println("    got to F"); 
            id_of_user = result_b.getId(); 
            System.out.println("    got to G"); 
            if( result_b.getPasssword().equals( Utils.generateShaOfString(bb))) { 
                System.out.println("    got to H"); 
                out_bool = true; 
            } 
        } 
        System.out.println("    exiting  UserDAO.validateIt with:" + out_bool); 
        return out_bool; 
      } 
     
      @SuppressWarnings("unchecked") 
      public User getUniqueObj( String aa) 
      { 
        List<User> results = null; 
        User result = null; 
        String sqlcmd; 
         
        sqlcmd = " FROM User WHERE userName = :kxa "; 
        Query hqlQuery = sf.getCurrentSession().createQuery( sqlcmd); 
        hqlQuery.setParameter( "kxa", aa); 
        results = hqlQuery.list(); 
        if( results.size() == 1) { 
            result = results.get(0); 
        } 
         
        return result; 
      } 
       
    } 



and the relavent parts of my stripped-down app. All it does is accept two string values and has two Login buttons.
Each calls validateAgainstDB which in turn calls the the DAO's validateIt method.
Code:
            //Create a button 
            buttonLoginA.setPreferredSize( new Dimension(90, 30)); 
            buttonLoginA.setMaximumSize( new Dimension(90, 30)); 
            buttonLoginA.setAlignmentX(Component.RIGHT_ALIGNMENT); 
            buttonLoginA.setToolTipText("click to log in to application"); 
            buttonLoginA.addActionListener( new ActionListener() { 
                public void actionPerformed( ActionEvent e) { 
                    SwingWorker worker8 = new SwingWorker<Object, Void>() { 
                        protected String doInBackground() throws InterruptedException { 
                            if( validateAgainstDB( nameOfUser.getText(), passwordOfUser.getText(), appName, serno)) { 
                                msgA.setText("A user logged in: " + currUser.getUsername()); 
                                msgB.setText("xxx"); 
                                System.out.println("yea, validation worked for A"); 
                            } else { 
                                System.out.println("boo, validation FAILED for A");           
                            } 
                            return "yea"; 
                        } 
                        protected void done() { 
     
                        } 
                      }; 
                      worker8.execute(); 
                  } 
            }); 
     
            //Create a button     also works 
            buttonLoginB.setPreferredSize( new Dimension(90, 30)); 
            buttonLoginB.setMaximumSize( new Dimension(90, 30)); 
            buttonLoginB.setAlignmentX(Component.RIGHT_ALIGNMENT); 
            buttonLoginB.setToolTipText("click to log in to application"); 
            buttonLoginB.addActionListener( new ActionListener() { 
                public void actionPerformed( ActionEvent e) { 
                    if( validateAgainstDB( nameOfUser.getText(), passwordOfUser.getText(), appName, serno)) { 
                        msgA.setText("xxx"); 
                        msgB.setText("B user logged in: " + currUser.getUsername()); 
                        System.out.println("yea, validation worked for B"); 
                    } else { 
                        System.out.println("boo, validation FAILED for B");           
                    } 
                } 
            }); 
         ........... 
         
        public boolean validateAgainstDB( String aa, String bb, String cc, String dd) 
        {   
            boolean out_bool = false; 
             
            if( this.userDAO.validateIt(aa, bb, cc, dd)) { 
                System.out.println("should get to here when validation is successfull"); 
                this.currUser = this.userDAO.getUniqueObj(aa); 
                out_bool = true; 
            } 
     
            return out_bool; 
        } 
     
        public static void main( String[] args) 
        { 
            //Schedule a job for the event-dispatching thread: 
            //creating and showing this application's GUI. 
            javax.swing.SwingUtilities.invokeLater( new Runnable() { 
                public void run() { 
     
                    String inn_str, tmp_str, roww; 
             
                    Problem theApp; 
             
                    theApp = new Problem(); 
                     
                    ApplicationContext ctx = new ClassPathXmlApplicationContext("ApplicationContext.xml"); 
                     
                    org.hibernate.SessionFactory sfA = (SessionFactory)                ctx.getBean("sessionFactoryA", SessionFactory.class); 
                    theApp.sessA = sfA.openSession(); 
     
                    theApp.userDAO    = (UserDAO)  ctx.getBean("userDAO"); 
                     
                    org.hibernate.SessionFactory sfB = (SessionFactory)                ctx.getBean("sessionFactoryB", SessionFactory.class); 
                    theApp.sessB = sfB.openSession(); 
                     
                    theApp.createAndShowGUI(); 
                     
                } 
            }); 
        } 


executing opens the GUI just fine, I fill in the username and password, click the LoginA button , validateAgainstDB gets called, UserDAOHibernate.validateIt gets called,
"got to A" gets printed then the program stalls on line 46. No error msgs, nothing, like an infinite wait-state. Commenting out lines 46-62 and forcing
out_bool = true at the top of the method allows the program to work perfectly.

So I am at a loss - how could this be happening, and how do I debug something when there's no messages or errors thrown?

I'm so frustrated, I'll even throw some cold hard cash on getting this solved - anyone living within 30mi of Arizona State University wants to take a crack at this,
I'll meet them with my laptop and if they can get this working it's worth USD50.00.

Or if you're further away but still want a crack at it, I could zip up some scripts and send it to you. You'd have to create a User table and populate it with one row, the adjust a properties file to point to your database.

TIA,

Still-learning Steve


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:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.