日期:2014-05-19  浏览次数:20791 次

hibernate查询问题 在线等你
我有两个例是多对一的关系,Category为一方,Product为多方,一方Product有个List<Product> products,多方Category有个Category category成员变量,当时是按这个自动生成的表
一方:
<class name="com.yuan.love.model.Category" table="category">
<id name="c_id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="c_name" type="java.lang.String"></property>
<set name="c_product">
<key column="c_id"></key>
<one-to-many class="com.yuan.love.model.Product"/>
</set>
</class>
多方:
<class name="com.yuan.love.model.Product" table="product">
<id name="p_id" type="java.lang.Integer">
<generator class="native"></generator>
</id>
<property name="p_name" type="java.lang.String">
<column name="p_name" length="30" not-null="true"></column>
</property>
<property name="p_model" type="java.lang.String">
<column name="p_model" length="20" not-null="true"></column>
</property>
<property name="p_pic" type="java.lang.String">
<column name="p_pic" length="30" not-null="true"></column>
</property>
<property name="p_detail" type="java.lang.String">
<column name="p_detail" length="500" ></column>
</property>
<property name="p_update" type="date">
<column name="p_update" length="30" not-null="true"></column>
</property>
<many-to-one name="category" column="c_id"></many-to-one>
</class>

生成表后多方里多了个c_id
用action查询find("from Product")后出现如下错误
select product0_.p_id as p1_3_, product0_.category_c_id as category7_3_, product0_.p_detail as p2_3_, product0_.p_model as p3_3_, product0_.p_name as p4_3_, product0_.p_pic as p5_3_, product0_.p_update as p6_3_ from Product product0_
Hibernate: select product0_.p_id as p1_3_, product0_.category_c_id as category7_3_, product0_.p_detail as p2_3_, product0_.p_model as p3_3_, product0_.p_name as p4_3_, product0_.p_pic as p5_3_, product0_.p_update as p6_3_ from Product product0_
22:56:10,094 WARN JDBCExceptionReporter:233 - SQL Error: 1054, SQLState: 42S22
22:56:10,094 ERROR JDBCExceptionReporter:234 - Unknown column 'product0_.category_c_id' in 'field list'

------解决方案--------------------
你看一下这个吧!刚csdn维护 不能发
http://blog.sina.com.cn/s/blog_63a2257a0100i6e0.html
------解决方案--------------------