Hibernate noob problem - Named query not known

From: Alan (nomorezpam3_at_hotmail.com)
Date: 08/17/04

  • Next message: Paul Thomas: "Re: postgreSQL v. MySQL?"
    Date: 17 Aug 2004 09:07:53 -0700
    
    

    I'm just scratching the surface of Hibernate at the moment and I'm
    running into problems.

    I'm trying it out with Eclipse, Hibernate Synchronizer and MySQL and
    things are vaguely working I think - although I can't seem to get
    Middlegen to work with this environment due to a seeming lack of
    documentation.

    Anyway - I've got this table trio - login, supplier and country. A
    login can have one supplier and one country; the DDL for these is
    shown below....

    create table login (
     login_id int NOT NULL AUTO_INCREMENT,
     login_cd char(16),
     login_nm varchar(80),
     email_address varchar(80),
     pwd varchar(16),
     login_count int,
     country_id int,
     supplier_id int,
     city_nm varchar(255),
     position_desc varchar(255),
     admin_fl char(1),
     version int,
     update_dt datetime,
     primary key(login_id),
     foreign_key(supplier_id) references supplier(supplier_id),
     foreign_key(country_id) references country(country_id)
    );

    create table country (
     country_id int NOT NULL AUTO_INCREMENT,
     country_cd char(16),
     country_nm varchar(255),
     version int,
     update_dt datetime,
     primary key(country_id)
    );

    create table supplier (
     supplier_id int NOT NULL AUTO_INCREMENT,
     supplier_cd char(16),
     supplier_nm varchar(80),
     supplier_logo_url varchar(255),
     supplier_desc text,
     supplier_url varchar(255),
     supplier_contact_email varchar(80),
     submitter_email varchar(80),
     submitter_name varchar(80),
     submitter_login_id int,
     version int,
     update_dt datetime,
     primary key(supplier_id)
    );

    I've been able to Hibernate Synchronize these tables using hbm

    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC
            "-//Hibernate/Hibernate Mapping DTD//EN"
            "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

    <hibernate-mapping package="com.mzuzu.test.hibernate.mapping">
            <class name="Login" table="login">
                    
                    <id name="LoginId" type="integer" unsaved-value="null">
                            <column name="login_id" sql-type="integer" not-null="true"/>
                            <generator class="native"/>
                     </id>
                    <one-to-one name="country"
    class="com.test.hibernate.mapping.Country" constrained="true"/>
                    <property column="position_desc" length="255" name="PositionDesc"
    not-null="false" type="string"/>
                    <many-to-one name="supplier" column="supplier_id"
    class="com.test.hibernate.mapping.Supplier"/>
                    <property column="login_cd" length="16" name="LoginCd"
    not-null="false" type="string"/>
                    <property column="city_nm" length="255" name="CityNm"
    not-null="false" type="string"/>
                    <property column="login_count" length="11" name="LoginCount"
    not-null="false" type="integer"/>
                    <property column="login_nm" length="80" name="LoginNm"
    not-null="false" type="string"/>
                    <property column="admin_fl" length="1" name="AdminFl"
    not-null="false" type="string"/>
                    <property column="update_dt" length="19" name="UpdateDt"
    not-null="false" type="timestamp"/>
                    <property column="version" length="11" name="Version"
    not-null="false" type="integer"/>
                    <property column="pwd" length="16" name="Pwd" not-null="false"
    type="string"/>
            </class>
    </hibernate-mapping>

    ... I'm not totally confident of the impact of the one-to-one and
    many-to-one tags - but this doesn't seem to be an issue at the moment.

    The problem I have is that I've got a getCountryByCd(..) method in my
    generated CountryDAO (see below) .....

         public class CountryDAO extends BaseCountryDAO {
            private static String BY_CD = "where country_cd = :country_cd";
            public static Country getCountryByCd(String code) throws
    HibernateException {
                    Session session = _RootDAO.createSession();
                    try {
                            Query query = session.getNamedQuery(BY_CD);
                            query.setString("country_cd", code);
                            return (Country)query.list().get(0);
                    }
                    finally {
                            session.close();
                    }
            }
       }

    .... that when I run it gives me a message that states :-

    .
    .
    .
    .
    INFO: starting update timestamps cache at region:
    net.sf.hibernate.cache.UpdateTimestampsCache
    17-Aug-2004 16:31:51 net.sf.ehcache.config.Configurator configure
    WARNING: No configuration found. Configuring ehcache from
    ehcache-failsafe.xml found in the classpath:
    jar:file:/C:/Java/hibernate-2.1/lib/ehcache-0.7.jar!/ehcache-failsafe.xml
    17-Aug-2004 16:31:51 net.sf.ehcache.hibernate.Plugin <init>
    WARNING: Could not find configuration for
    net.sf.hibernate.cache.UpdateTimestampsCache. Configuring using the
    defaultCache settings.
    17-Aug-2004 16:31:51 net.sf.hibernate.cache.QueryCache <init>
    INFO: starting query cache at region:
    net.sf.hibernate.cache.QueryCache
    17-Aug-2004 16:31:51 net.sf.ehcache.hibernate.Plugin <init>
    WARNING: Could not find configuration for
    net.sf.hibernate.cache.QueryCache. Configuring using the defaultCache
    settings.
    main Exception net.sf.hibernate.MappingException: Named query not
    known: where country_cd = :country_cd

    I cannot find any mention of this "Named query not known" or why it
    might come out. Has anyone got any suggestions where I might look for
    a solution?

    Many thanks
    Alan


  • Next message: Paul Thomas: "Re: postgreSQL v. MySQL?"

    Relevant Pages