facebook

[Closed] NoClassDefFoundError and Query.list() failure

  1. MyEclipse Archived
  2.  > 
  3. Database Tools (DB Explorer, Hibernate, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #247380 Reply

    peterharris
    Member

    Help please,

    I am trying to run through various hibernate turorials and have run up against a brick wall. I can load individual records with no problems, but cannot load a list of records using the Query.list() funtion.

    I hope this is just me doing something dumb. Setup and code below. Any help greatfully received.

    Thanks

    
    -----------------------------------------------------------------------    
    Stack Trace
    -----------------------------------------------------------------------    
    Exception in thread "main" java.lang.NoClassDefFoundError: antlr/ANTLRException
        at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:27)
        at org.hibernate.impl.SessionFactoryImpl.createQueryTranslators(SessionFactoryImpl.java:357)
        at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:423)
        at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:884)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:834)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
        at com.hammerhead.hibernate.MemberViewer.loadMembers(MemberViewer.java:82)
        at com.hammerhead.hibernate.MemberViewer.main(MemberViewer.java:111)
        
    -----------------------------------------------------------------------    
    Java Function
    -----------------------------------------------------------------------    
      public void loadMembers() {
    
            try {
                Session mySesh = SessionManager.currentSession();
                Transaction tx = mySesh.beginTransaction();
    
                log.info("Loading Members");
                
                System.out.println("===================");
    
                Members myMember = new Members();
    
                String hql = "from Members as myMember";
    //
                Query q = mySesh.createQuery(hql);
                List memberList = q.list();
                tx.commit();
                System.out.println("===================");
                for (Iterator iter=memberList.iterator(); iter.hasNext(); ) {
                    myMember = (Members) iter.next(); 
                    System.out.println("    -------------------");
                    System.out.println("    MemberID : " + myMember.getPkid() );
                    System.out.println("    Name     : " + myMember.getUsername() );
                    System.out.println("    Name     : " + myMember.getFullname() );
                    System.out.println("    Name     : " + myMember.getEmail() );
                    System.out.println("    -------------------");
                }
                
            } catch (Exception e) {
                System.out.println("===================");
                log.info("Fail - Loading Members");
                System.out.println("Uh-Ohhh. V. E. R. N.");
                e.printStackTrace();
                System.out.println("===================");
            }
                
        }
    -----------------------------------------------------------------------    
    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">
    
    <!-- Generated by MyEclipse Hibernate Tools.                   -->
    <hibernate-configuration>
    
    <session-factory>
        <property name="myeclipse.connection.profile">HammerHead</property>
        <property name="connection.url">
            jdbc:mysql://192.168.0.3:3306/hammerhead
        </property>
        <property name="connection.username">spong</property>
        <property name="connection.password"></property>
        <property name="connection.driver_class">
            com.mysql.jdbc.Driver
        </property>
        <property name="dialect">
            org.hibernate.dialect.MySQLDialect
        </property>
        <property name="max_fetch_depth">1</property>
        <mapping resource="com/hammerhead/hibernate/Members.hbm.xml"></mapping>
    
    
    </session-factory>
    
    </hibernate-configuration>
    
    -----------------------------------------------------------------------    
    Members.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" >
    
    <!-- DO NOT EDIT: This is a generated file that is synchronized -->
    <!-- by MyEclipse Hibernate tool integration.                   -->
    <!-- Created Sun Feb 26 21:11:40 GMT 2006                         -->
    <hibernate-mapping package="com.hammerhead.hibernate">
    
        <class name="Members" table="members">
            <id name="pkid" column="pkid" type="integer">
                <generator class="increment"/>
            </id>
     
            <property name="username" column="UserName" type="string"  not-null="true" />
            <property name="fullname" column="FullName" type="string"  not-null="true" />
            <property name="email" column="EMail" type="string"  not-null="true" />
            <property name="group" column="Group" type="short"  not-null="true" />
            <property name="password" column="Password" type="string"  not-null="true" />
        </class>
        
    </hibernate-mapping>
    
    -----------------------------------------------------------------------    
    DB Schema
    -----------------------------------------------------------------------    
    # Table structure for table `members`
    
    CREATE TABLE `members` (
      `pkid` mediumint(8) unsigned NOT NULL auto_increment,
      `UserName` varchar(20) NOT NULL default '',
      `FullName` varchar(80) NOT NULL default '',
      `EMail` tinytext NOT NULL,
      `Group` tinyint(3) unsigned NOT NULL default '0',
      `Password` varchar(64) NOT NULL default '',
      PRIMARY KEY  (`pkid`),
      FULLTEXT KEY `UserName` (`UserName`,`FullName`,`Password`)
    ) TYPE=MyISAM AUTO_INCREMENT=5 ;
    
    # Dumping data for table `members`
    
    INSERT INTO `members` VALUES (1, 'peterh', 'Peter Harris', 'bob@hh.ie', 1, '76ce50d150b743c6');
    INSERT INTO `members` VALUES (2, 'tracyc', 'Tracy Culleton', 'tracy@hh.ie', 0, '07a4b1453a806bb3');
    INSERT INTO `members` VALUES (3, 'tadhgh', 'Tadhg harris', 'tadhg@hh.ie', 0, 'ginger');
    INSERT INTO `members` VALUES (4, 'minnieh', 'Minnie The Poocher', 'minnie@hh.ie', 0, 'grrrrrr6');
    
    
    -----------------------------------------------------------------------    
    Config
    -----------------------------------------------------------------------    
    Dev OS      Win XP
    Eclipse               3.1
    myEclipse             4.0
    mysql_connector_java  3.1.12
    JDK                   5.0
    
    Server OS   Suse 9.3
    mySQL                 4.0.16
    [/code/
    #247384 Reply

    Riyad Kalla
    Member

    Exception in thread “main” java.lang.NoClassDefFoundError: antlr/ANTLRException
    at org.hibernate.hql.ast.ASTQueryTranslatorFactory.createQueryTranslator(ASTQueryTranslatorFactory.java:27)

    No need to read farther, just fix this. You need to find and add antrl to your build path for Hibernate. If you are using MyEclipse, this should have been included as “antlr-2.7.5H3.jar” in your Hibernate 3 Core library. If you added Hibernate libraries yourself, go back to the libs you used and grab the antrl JAR and throw it into your WEB-INF/lib directory.

    #247400 Reply

    peterharris
    Member

    Many thanks Riyad,
    Had to get the jar from the hibernate site, but once installed and a few code corrections, life is wonderful.

    Thanks for your prompt response.

    Good product, good support. It doesn’t get much better than this.

    #247408 Reply

    Riyad Kalla
    Member

    Glad to hear you are back in action.

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: [Closed] NoClassDefFoundError and Query.list() failure

You must be logged in to post in the forum log in