Menu

can't query

Help
Anonymous
2003-10-04
2003-12-17
  • Anonymous

    Anonymous - 2003-10-04

    Hi
    I have set up the plugin to connect to a database.
    This works fine because I can export/update schema. But I can't query...select name from Poll results in an unknown alias error. I noticed someone has mentioned this in the bugs section...is it a bug or is there something I haven't done?
    Many thanks,
    Al

     
    • Daniel Bradby

      Daniel Bradby - 2003-10-04

      Have you tried just doing a simple query like "from Poll as poll".

       
    • Anonymous

      Anonymous - 2003-10-05

      I try that and it says error etc. null value was assigned to a property of primitive type setter of uk.co.ritmos.Poll.active
      don't know what the active means
      something possibly a big odd in the log after connection before adding dependent files it says in orange:
      Ignoring resources in Project output: /ritmos1/WEB-INF/classes
      don't know whether that is of interest
      thanks, al

       
    • Ann Marie Amarga

      tried it too:

      from Person as person

      No luck.

       
    • Daniel Bradby

      Daniel Bradby - 2003-10-09

      The "Ignoring resources in Project output: /ritmos1/WEB-INF/classes
      " is just a note to sya that the mapping files that are duplicated in your output location will be ignored so it won't load them twice.

      Do you have a stack trace along with the error message? Is the error coming from inside Hibernate itself?

       
    • Anonymous

      Anonymous - 2003-11-21

      I have installed Hibernator 0.9.6 and using it with Eclipse 2.1.1 and Oracle db. I try to run a simple query SELECT errorcode from ErrorLog and get an error "undefined alias errorcode [select errorcode from ErrorLog]" I have also tried "errorcode as code", "from ErrorLog as code" etc etc but the same result. Here is what I see in the Hibernator Log. Will appreciate any help.

      select errorcode from ErrorLog
      net.sf.hibernate.QueryException: undefined alias: errorcode [select errorcode from ErrorLog]
          at net.sf.hibernate.hql.PathExpressionParser.token(PathExpressionParser.java:110)
          at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:29)
          at net.sf.hibernate.hql.SelectParser.token(SelectParser.java:153)
          at net.sf.hibernate.hql.ClauseParser.token(ClauseParser.java:87)
          at net.sf.hibernate.hql.ClauseParser.end(ClauseParser.java:114)
          at net.sf.hibernate.hql.PreprocessingParser.end(PreprocessingParser.java:140)
          at net.sf.hibernate.hql.ParserHelper.parse(ParserHelper.java:30)
          at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:146)
          at net.sf.hibernate.hql.QueryTranslator.compile(QueryTranslator.java:133)
          at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:352)
          at net.sf.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:330)
          at net.sf.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1368)
          at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1332)
          at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1322)
          at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1314)
          at net.sf.hibernator.HibernateConnection.query(HibernateConnection.java:188)
          at net.sf.hibernator.views.QueryView$QueryTask.run(QueryView.java:255)
          at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:101)

       
    • Daniel Bradby

      Daniel Bradby - 2003-11-21

      What is the name of your class? What package is your class in?

       
    • Anonymous

      Anonymous - 2003-11-21

      Appreciate the super fast response! I think I may have figured out my problem. I was trying to use QueryView as a normal SQL editor and not as a HQL editor.
      But I have run into a mapping issue now. I have a

      class ErrorCode = {private int id;
          private String progName;
          private String errorCode;
          private String errorText; }
      I have defined corresp get/set methods as well.

      The Oracle database table is defined as
      ErrorCode { SEQUENCENO NUMBER,
      PROGNAME VARCHAR2(100),
      ERRORCODE VARCHAR2(100),
      ERRORTEXT VARCHAR2(500) }

      The ErrorCode.hbm.xml is defined as
      <hibernate-mapping>
          <class name="com.nexgenix.ix.test.ErrorCode" table="ERRORCODE">
              <id name="id">
                  <column name="SEQUENCENO" sql-type="NUMBER" not-null="true"/>
                  <generator class="sequence">
                      <param>seq_errorcode</param>
                  </generator>
              </id>

              <property name="progName">
                  <column name="PROGNAME" sql-type="VARCHAR2(100)" not-null="false"/>
              </property>
              <property name="errorCode"/>
              <property name="errorText"/>
          </class>

      </hibernate-mapping>

      And when I try to connect I get the exception
      java.lang.NullPointerException
          at java.util.Hashtable.put(Hashtable.java:398)
          at java.util.Properties.setProperty(Properties.java:102)
          at net.sf.hibernate.cfg.Binder.makeIdentifier(Binder.java:835)
          at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:233)
          at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1095)
          at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230)
          at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:155)
          at net.sf.hibernator.HibernateConnection.createConnection(HibernateConnection.java:168)
          at net.sf.hibernator.views.ConnectionView$8.run(ConnectionView.java:199)
          at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:101)
      rethrown as net.sf.hibernate.MappingException
          at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:159)
          at net.sf.hibernator.HibernateConnection.createConnection(HibernateConnection.java:168)
          at net.sf.hibernator.views.ConnectionView$8.run(ConnectionView.java:199)
          at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:101)
      Caused by: java.lang.NullPointerException
          at java.util.Hashtable.put(Hashtable.java:398)
          at java.util.Properties.setProperty(Properties.java:102)
          at net.sf.hibernate.cfg.Binder.makeIdentifier(Binder.java:835)
          at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:233)
          at net.sf.hibernate.cfg.Binder.bindRoot(Binder.java:1095)
          at net.sf.hibernate.cfg.Configuration.add(Configuration.java:230)
          at net.sf.hibernate.cfg.Configuration.addFile(Configuration.java:155)
          ... 3 more

      I am new to Hibernate and sorry if something similar has been posted before. Just eager to get my first app running.
      Thanks!

       
      • Emanuele P.

        Emanuele P. - 2003-12-15

        I'm having the same problem like anandam: net.sf.hibernate.QueryException: undefined alias, making a simple query. Which was the solution for that problem?

        Thanks!

         
        • Anonymous

          Anonymous - 2003-12-16

          According to DTD (2.0), generator should be as following.
          <generator class="sequence">
          <param name="sequence">seq_errorcode</param>
          </generator>
          should not
          <generator class="sequence">
          <param>seq_errorcode</param>
          </generator>

           
          • Emanuele P.

            Emanuele P. - 2003-12-16

            I'm at the beginning using Hibernator, so I don't understand where I should insert this code. May you say to me where I should place it?

             
            • Anonymous

              Anonymous - 2003-12-16

              Thats is for the case of anandam.
              I said that the id generator descriptor looks like invalid.
              And cause following exception.
              I don't know the solution for 'unknown alias error'.
              BTW, did you made the mapping file for the entity named 'Poll'?

              And when I try to connect I get the exception
              java.lang.NullPointerException
              at java.util.Hashtable.put(Hashtable.java:398)
              at java.util.Properties.setProperty(Properties.java:102)
              at net.sf.hibernate.cfg.Binder.makeIdentifier(Binder.java:835)
              at net.sf.hibernate.cfg.Binder.bindRootClass(Binder.java:233)

               
              • Anonymous

                Anonymous - 2003-12-16

                Emanuele,
                I got the undefined alias because I was trying to use the Hibernator query view as a simple SQL query view. Hibernator query view works with HQL and you have to define the O-R mapping before executing a query in the Hibernators query view..
                Here is what I had to do. My query was something like select errormsg from errorcode
                1. I had an ErrorCode class which mapped to my ErrorCode table in the Oracle database
                2. Defined the O-R mapping in xml format (Hibernator provides you with a template for this xml. eg 'yourclassname'.hbm.xml)
                3. Refer to Hibernator documentation for syntax etc. You can also refer to one of my earlier posts where I have given details about my Java class, Oracle table and the mapping xml.
                Hope that helps!

                 
                • Emanuele P.

                  Emanuele P. - 2003-12-16

                  Two questions:

                  1. After having defined an XML mapping, should I use Query View as a normal query editor or I need to use a particular sintax?

                  2. How can I create database table automatically after having defined a bean with Hibernator?

                   
                  • Anonymous

                    Anonymous - 2003-12-16

                    You have to query with Hibernate Query Language.
                    For generating mapping descriptor, you can use XDoclet or Database plugins.
                    XDoclet generates from the comments of java source.
                    Some Database plugins (I know JFaceDbc does it) support mapping descriptor generation from exisiting database schema.

                     
                  • Anonymous

                    Anonymous - 2003-12-17

                    One more another way to create the mapping descriptor, open the hibernator view and point the java source on package explorer.
                    The hibernator view show the mapping descriptor.
                    It might be modified for use.

                    > 2. How can I create database table automatically after having defined a bean with Hibernator

                    Once you have created the mapping descriptor, Create button of hibernator create the table for the entities including (primary/foreign key) constraints.

                     
                    • Emanuele P.

                      Emanuele P. - 2003-12-17

                      Thank you for your help. It's starting to work!

                       

Log in to post a comment.