我的dao中是这样写的:
public List findByProperty(String propertyName, Object value) {
log.debug("finding ReptAgilityConfig instance with property: "
+ propertyName + ", value: " + value);
try {
String queryString = "from ReptAgilityConfig as model";
return getHibernateTemplate().find(queryString);
} catch (RuntimeException re) {
log.error("find by property name failed", re);
throw re;
}
}
返回的list是空的。
还有啊,我用myeclipse自动把数据库中的表映射成hibernate所需要的类,生成了2个,一个ReptAgilityConfig,里面只有一个id;另一个是ReptAgilityConfigId,里面对应了数据库表中的一些字段。在上面的dao中,propertyName填成表中的任意字段都会出错(因为它只有一个成员id),那么我该怎么用它呢?
高手来帮我啊,我只有这么多分了。

解决方案 »

  1.   

    把from ReptAgilityConfig as model写成from ReptAgilityConfig,试试看
      

  2.   

    最好是把表、MAP文件、类放上来看看
      

  3.   

    public List findByProperty(String propertyName, Object value)
    你不用这个方法 自己写个方法啊  
        public List findByYzdh() {
            log.debug("finding GsTjjlTzjlcxView instance with property " );
            try {
               String queryString = "from ReptAgilityConfig ;
        return getHibernateTemplate().find(queryString);
            } catch (RuntimeException re) {
               log.error("find by property name failed", re);
               throw re;
            }
       }
    在ReptAgilityConfig 前面写上它的路径
      

  4.   

    我把from ReptAgilityConfig as model写成from ReptAgilityConfig还是一样的问题。我的表:
    create table REPT_AGILITY_CONFIG
    (
      PRODUCT_NAME VARCHAR2(255),
      EXECUTE_SQL  VARCHAR2(4000),
      LOCAL_NET_ID NUMBER,
      COLUMN_NAME  VARCHAR2(1024),
      STS          VARCHAR2(3),
      WORK_AREA_ID NUMBER
    )
    放在服务器上的。ReptAgilityConfig.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">
    <!-- 
        Mapping file autogenerated by MyEclipse - Hibernate Tools
    -->
    <hibernate-mapping>
        <class name="com.yourcompany.ReptAgilityConfig" table="REPT_AGILITY_CONFIG" schema="CONV97">
            <composite-id name="id" class="com.yourcompany.ReptAgilityConfigId">
                <key-property name="productName" type="java.lang.String">
                    <column name="PRODUCT_NAME" />
                </key-property>
                <key-property name="executeSql" type="java.lang.String">
                    <column name="EXECUTE_SQL" length="4000" />
                </key-property>
                <key-property name="localNetId" type="java.lang.Long">
                    <column name="LOCAL_NET_ID" precision="22" scale="0" />
                </key-property>
                <key-property name="workAreaId" type="java.lang.Long">
                    <column name="WORK_AREA_ID" precision="22" scale="0" />
                </key-property>
                <key-property name="columnName" type="java.lang.String">
                    <column name="COLUMN_NAME" length="1024" />
                </key-property>
                <key-property name="sts" type="java.lang.String">
                    <column name="STS" length="3" />
                </key-property>
            </composite-id>
        </class>
    </hibernate-mapping>ReptAgilityConfig.class:
    package com.yourcompany;/**
     * ReptAgilityConfig generated by MyEclipse - Hibernate Tools
     */public class ReptAgilityConfig  implements java.io.Serializable {
        // Fields         private ReptAgilityConfigId id;
        // Constructors    /** default constructor */
        public ReptAgilityConfig() {
        }    
        /** full constructor */
        public ReptAgilityConfig(ReptAgilityConfigId id) {
            this.id = id;
        }   
        // Property accessors    public ReptAgilityConfigId getId() {
            return this.id;
        }
        
        public void setId(ReptAgilityConfigId id) {
            this.id = id;
        }
       
    }ReptAgilityConfigId.class:
    package com.yourcompany;/**
     * ReptAgilityConfigId generated by MyEclipse - Hibernate Tools
     */public class ReptAgilityConfigId  implements java.io.Serializable {
        // Fields         private String productName;
         private String executeSql;
         private Long localNetId;
         private Long workAreaId;
         private String columnName;
         private String sts;
        // Constructors    /** default constructor */
        public ReptAgilityConfigId() {
        }    
        /** full constructor */
        public ReptAgilityConfigId(String productName, String executeSql, Long localNetId, Long workAreaId, String columnName, String sts) {
            this.productName = productName;
            this.executeSql = executeSql;
            this.localNetId = localNetId;
            this.workAreaId = workAreaId;
            this.columnName = columnName;
            this.sts = sts;
        }   
        // Property accessors    public String getProductName() {
            return this.productName;
        }
        
        public void setProductName(String productName) {
            this.productName = productName;
        }    public String getExecuteSql() {
            return this.executeSql;
        }
        
        public void setExecuteSql(String executeSql) {
            this.executeSql = executeSql;
        }    public Long getLocalNetId() {
            return this.localNetId;
        }
        
        public void setLocalNetId(Long localNetId) {
            this.localNetId = localNetId;
        }    public Long getWorkAreaId() {
            return this.workAreaId;
        }
        
        public void setWorkAreaId(Long workAreaId) {
            this.workAreaId = workAreaId;
        }    public String getColumnName() {
            return this.columnName;
        }
        
        public void setColumnName(String columnName) {
            this.columnName = columnName;
        }    public String getSts() {
            return this.sts;
        }
        
        public void setSts(String sts) {
            this.sts = sts;
        }
          public boolean equals(Object other) {
             if ( (this == other ) ) return true;
     if ( (other == null ) ) return false;
     if ( !(other instanceof ReptAgilityConfigId) ) return false;
     ReptAgilityConfigId castOther = ( ReptAgilityConfigId ) other; 
             
     return ( (this.getProductName()==castOther.getProductName()) || ( this.getProductName()!=null && castOther.getProductName()!=null && this.getProductName().equals(castOther.getProductName()) ) )
     && ( (this.getExecuteSql()==castOther.getExecuteSql()) || ( this.getExecuteSql()!=null && castOther.getExecuteSql()!=null && this.getExecuteSql().equals(castOther.getExecuteSql()) ) )
     && ( (this.getLocalNetId()==castOther.getLocalNetId()) || ( this.getLocalNetId()!=null && castOther.getLocalNetId()!=null && this.getLocalNetId().equals(castOther.getLocalNetId()) ) )
     && ( (this.getWorkAreaId()==castOther.getWorkAreaId()) || ( this.getWorkAreaId()!=null && castOther.getWorkAreaId()!=null && this.getWorkAreaId().equals(castOther.getWorkAreaId()) ) )
     && ( (this.getColumnName()==castOther.getColumnName()) || ( this.getColumnName()!=null && castOther.getColumnName()!=null && this.getColumnName().equals(castOther.getColumnName()) ) )
     && ( (this.getSts()==castOther.getSts()) || ( this.getSts()!=null && castOther.getSts()!=null && this.getSts().equals(castOther.getSts()) ) );
       }
       
       public int hashCode() {
             int result = 17;
             
             result = 37 * result + ( getProductName() == null ? 0 : this.getProductName().hashCode() );
             result = 37 * result + ( getExecuteSql() == null ? 0 : this.getExecuteSql().hashCode() );
             result = 37 * result + ( getLocalNetId() == null ? 0 : this.getLocalNetId().hashCode() );
             result = 37 * result + ( getWorkAreaId() == null ? 0 : this.getWorkAreaId().hashCode() );
             result = 37 * result + ( getColumnName() == null ? 0 : this.getColumnName().hashCode() );
             result = 37 * result + ( getSts() == null ? 0 : this.getSts().hashCode() );
             return result;
       }   }执行dao返回的list.toString()为[null, null, null, null, null, null],我都摸不着头脑了。
    我这里的分不多,但我非常希望论坛里有经验的人,哪怕是只有一点经验的人热情的帮助我。谢谢了。
      

  5.   

    什么意思???怎样解决的啊??我的findproperty()怎么都是空啊。