亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

hibernate 單項多對一 查詢問題

查詢語句

public?static?void?loadStudent()?{
??Session?session?=?HibernateSessionFactory.openSession();?
??Student?s1?=?(Student)?session.load(Student.class,?1);
??//已重寫tostring
??System.out.println(s1);
??//System.out.println(s1.getClassTable());
?}

xml配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
??? "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
??? "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
???
<hibernate-mapping auto-import="true" package="com.hellojava.entity">
?<class name="Student" table="student">
?? <id name="stuId" column="stuId" type="integer">
?? ?<generator class="increment"></generator>
?? </id>
?? <property name="stuName" column="stuName" type="string" length="20"></property>
?? <property name="stuSex" column="stuSex" type="character" length="6"></property>
?? <property name="stuAge" column="stuAge" type="integer"></property>

<!-- 必須加上此才能查詢出外鍵列insert="true" update="true"?-->

<!--
?? <property name="cid" column="cid" type="integer" insert="true" update="true"></property>?? -->


?? <many-to-one name="classTable" class="ClassTable" column="cid"></many-to-one>
?</class>
</hibernate-mapping>

求解?

正在回答

3 回答

Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.hellojava.entity.Student column: cid (should be mapped with insert="false" update="false")

?<!--?insert="false"?update="false"?才可以查詢出cid?-->
???<!--?<property?name="cid"?column="cid"?type="integer"?insert="false"?update="false"></property>?-->
???<property?name="cid"?column="cid"?type="integer"></property>

不明白為什么? 必須添加? <!-- insert="false" update="false" 才可以查詢出cid -->

0 回復 有任何疑惑可以回復我~

能不能把你的問題貼出來看看,查不到結果么???

0 回復 有任何疑惑可以回復我~

<many-to-one>中的class屬性沒寫錯么??地址???

0 回復 有任何疑惑可以回復我~
#1

進擊的小白菜 提問者

那個沒問題的,配置了這個<hibernate-mapping auto-import="true" package="com.hellojava.entity"> 自動導入包名的
2016-12-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Hibernate初探之一對多映射
  • 參與學習       42163    人
  • 解答問題       310    個

Hibernate中一對多關聯映射配置,以及cascade和inverse屬性作用

進入課程

hibernate 單項多對一 查詢問題

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號