每日一得

          不求多得,只求一得 about java,hibernate,spring,design,database,Ror,ruby,快速開發
          最近關心的內容:SSH,seam,flex,敏捷,TDD
          本站的官方站點是:顛覆軟件

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            220 隨筆 :: 9 文章 :: 421 評論 :: 0 Trackbacks
          key words:hibernate,load,session.get,session.load()

          public?class?Parent?implements?Serializable?{

          ????
          /**?identifier?field?*/
          ????
          private?Long?id;

          ????
          /**?persistent?field?*/
          ????
          private?List?childs;

          ????
          /**?full?constructor?*/
          ????
          public?Parent(Long?id,?List?childs)?{
          ????????
          this.id?=?id;
          ????????
          this.childs?=?childs;
          ????}

          ????
          /**?default?constructor?*/
          ????
          public?Parent()?{
          ????}

          ????
          /**?
          ?????*????????????@hibernate.id
          ?????*?????????????generator-class="assigned"
          ?????*?????????????type="java.lang.Long"
          ?????*?????????????column="id"
          ?????*
          ?????
          */
          ????
          public?Long?getId()?{
          ????????
          return?this.id;
          ????}

          ????
          public?void?setId(Long?id)?{
          ????????
          this.id?=?id;
          ????}

          ????
          /**
          ?????*????????????@hibernate.set
          ?????*?????????????lazy="true"
          ?????*?????????????inverse="true"
          ?????*?????????????cascade="none"
          ?????*????????????@hibernate.collection-key
          ?????*?????????????column="parent_id"
          ?????*????????????@hibernate.collection-one-to-many
          ?????*?????????????class="net.foxlog.model.Child"
          ?????*?????????
          ?????
          */
          ????
          public?List?getChilds()?{
          ????????
          return?this.childs;
          ????}

          ????
          public?void?setChilds(List?childs)?{
          ????????
          this.childs?=?childs;
          ????}

          ????
          public?String?toString()?{
          ????????
          return?new?ToStringBuilder(this)
          ????????????.append(
          "id",?getId())
          ????????????.toString();
          ????}

          ????
          public?boolean?equals(Object?other)?{
          ????????
          if?(?!(other?instanceof?Parent)?)?return?false;
          ????????Parent?castOther?
          =?(Parent)?other;
          ????????
          return?new?EqualsBuilder()
          ????????????.append(
          this.getId(),?castOther.getId())
          ????????????.isEquals();
          ????}

          ????
          public?int?hashCode()?{
          ????????
          return?new?HashCodeBuilder()
          ????????????.append(getId())
          ????????????.toHashCode();
          ????}

          }


          Parent?parent?=?(Parent)session.load(Parent.class,new Integer(7));

          運行提示出錯,"can't get Entity.."

          知道是什么低級錯誤么?? 其實很弱智的東西,但是不注意還就會出現,呵呵,答案如下:


          posted on 2006-11-07 19:28 Alex 閱讀(1656) 評論(3)  編輯  收藏 所屬分類: Hibernate

          評論

          # re: Hibernate的load錯誤,你碰到過這樣的問題么? 2006-11-08 12:37 Alex
          ============還有load容易出問題,盡量用get吧  回復  更多評論
            

          # re: Hibernate的load錯誤,你碰到過這樣的問題么? 2007-01-08 01:08 癩蛤蟆的左眼
          我在Hibernate中的xml文件中定義了雙向映射,并附加了一個元素one-to-many產生的Set元素,并在持久化類用getSubSubject()取到了定義的Set集合,強制轉化成list行嗎?

          List list = (List)getSubSubject(); //Set getSubSubject() 是持久化類中提供的
          return list;

          程序沒有報錯,但驗證時發現getSubSubjects()取不出東西 ,而且一使用它就報錯 ,請問你遇到過嗎?  回復  更多評論
            

          # re: Hibernate的load錯誤,你碰到過這樣的問題么? 2007-01-12 16:46 大田斗
          呵呵,這個錯誤確實有點不好發現,其實使用get/load都能達到目的,相比之下load也許有時效率更高,終究查詢了一次二級緩存  回復  更多評論
            

          主站蜘蛛池模板: 汉中市| 峨山| 青浦区| 吉林省| 荆州市| 林周县| 武乡县| 巢湖市| 甘肃省| 肇州县| 霍邱县| 林周县| 博湖县| 金溪县| 梓潼县| 金寨县| 丹东市| 临安市| 扬州市| 新沂市| 深州市| 连江县| 郁南县| 固阳县| 宾川县| 寻乌县| 吴桥县| 东乌| 远安县| 木里| 融水| 无棣县| 科尔| 高阳县| 泸州市| 宝山区| 扶沟县| 安新县| 屯留县| 正定县| 张家口市|