<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    Duran's technical life
    踏踏實實學技術,認認真真做研究。

    環境:Hibernate 2.1.7 + MySQL4.1(MySQL的編碼已設置為utf8)
    問題:通過Hibernate向MySQL寫入中文后,通過Hibernate取回數據,在console中打印java對象顯示正常。但在MySQL Query Browser中看到的是亂碼,傳給前端的Flex也是亂碼。
    原因:Hibernate的基礎還是JDBC,所以一樣需要設置characterEncoding!
    解決方法
    在hibernate.cfg.xml中應該這樣寫

    <property name="connection.url">jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8</property>
    如果用hibernate.properties
    #hibernate.connection.url jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8

    ps:處理中文的話,characterEncoding用GBK一樣可以。
    但字節編碼問題最好的解決方法還是統一使用UTF-8!!!
    posted @ 2005-06-10 21:35 Duran's technical life 閱讀(15936) | 評論 (13)編輯 收藏
     
    Degrees and what they mean:
     BS  I can code, do basic technical work
     MS  More design responsibility and more independence
    PhD  Research, teaching, or architecting/design
    posted @ 2005-06-10 12:35 Duran's technical life 閱讀(528) | 評論 (0)編輯 收藏
     
    GUI編程太繁瑣,而且感覺相對而言“技術含量”不高。討厭也得學啊,畢竟寫的程序要通過GUI暴露給用戶。
    有的人笑話java的跨平臺是幌子,一次編寫,到處調試。我倒想問,怎樣該被稱做“幌子”。不同的操作系統之間的差異本來就很大,做到完全統一從原理上就是永遠不可能的。就像寫的再好的模擬器也只能達到99%的模擬程度!Swing其實已經不錯了,隨著jdk更新的每個版本都能有所改進。但是仍然遠沒達到讓人滿意的地步。一是表現力仍然很差,看Swing做的軟件Together、NetBeans……界面真的好丑!也看了一些第三方公司自己擴展Swing做出的demo,效果還不錯。要價幾k美刀,也不知開發效率如何。二就是開發效率仍然過低。“鄙視”vb、pb這樣的RAD工具,寫出來的代碼混亂沒架構,但是它們做GUI的效率很高。
    最期待的表現層技術還是M$的Avalon,M$雖然討厭,但它的開發環境對程序員是最友善的。
    說說Flex。Flex學習曲線不大,各種UI Component超好用。不爽的ActionScript語法好別扭,不習慣。現有的官方reference文檔太少了,更新又慢,例子也少得很。做東西時沒有pattern模仿,自己摸蠻痛苦而且寫出來的代碼也覺得有些cuo。
    posted @ 2005-06-07 23:18 Duran's technical life 閱讀(565) | 評論 (0)編輯 收藏
     

    Martin Fowler是ThoughtWorks的首席科學家。從80年代開始,他就一直從事軟件開發的工作。在80年代中期,他對面向對象開發這個新領域發生了興趣。他擅長在商業信息系統中加入面向對象的思想。時至21世紀,他又在UML推廣普及、領域建模、企業應用開發和敏捷方法等方面建樹卓著,被稱為軟件開發的教父。

    可惜他只去上海、北京,眼巴巴地看著啊。

    posted @ 2005-06-01 23:31 Duran's technical life 閱讀(288) | 評論 (0)編輯 收藏
     
    以前沒人考研的時候都是開考研動員大會,現在人招多了輔導員又開始勸大家條件不好的就盡量去找工作,呵呵。看上一屆就業單位名單里居然連“安利(中國)日用品有限公司”都有,真是暈菜死。
    posted @ 2005-06-01 23:24 Duran's technical life 閱讀(290) | 評論 (0)編輯 收藏
     
    考試周,明天晚上GF來,忙~~~自習去了。
    posted @ 2005-05-26 07:45 Duran's technical life 閱讀(380) | 評論 (1)編輯 收藏
     
         摘要: 參考package EDU.oswego.cs.dl.util.concurrent 1public interface Sync {2    public void acquire();3    public void release();4...  閱讀全文
    posted @ 2005-05-19 09:54 Duran's technical life 閱讀(1047) | 評論 (0)編輯 收藏
     
         廬山回來后就沒寫過blog了,不過每天晚上跑步倒是一直在堅持。寫blog的目的是對自己學習成長的記錄、反省和促進,貴在堅持。上個星期用java寫了個評估項目CPM的小程序,實踐了hibernate、xDoclet,練習了反復Refactor+TDD的開發方式,感覺很爽。當做到PERT計算功能時發現需要查正態分布表,google查了查沒找到第三方的java數學運算包。直到在圖書管看書時才發現用編程進行復雜的函數運算的方法是屬于《計算方法》課的,奇怪我們專業為什么不開這門課。發現自己知識結構上的一個空白。

        前幾天做操作系統作業,順便看了看《Concurrent Programming in Java: Design Principles and Patterns》,確信《程序員》第三期上關于Mutex的一段代碼完全是錯誤的,又給《程序員》編輯發了mail(上次發了mail后了無音訊)。沒想很快到過了收到編輯和作者的回復,確認了錯誤。倒不是說出了錯就說明作者水平不高,java相關技術太多了,軟件開發相關技術就更多了。我想說的的是搞軟件開發雖然是個智力活動,但終究談不上需要極高的天賦才行(不像數學這樣的基礎理論學科)。作者也是人,當然也會犯錯誤。國外的那些軟件大牛也是人,他們也是一步一步成長起來的,其實并不是在神壇上高不可攀。那為什么國內高手少呢?環境所致。記得好像是在白云上看過有個人說“Linus好牛,20歲就搞出了linux,我們20歲能干嗎”,下面有個人回帖說“那是他在Stanford,要是把你丟在那,你說不定也能做出個XXX來”。

        HeadStorm是我很欽佩的一位程序員,工作了幾年后憑著不停的學習、實踐對j2ee應用開發技術有了較高的造詣。在圈內取得一定成績后又及時地認清了自己的目標,做一個全面的技術高手,要“往下走”,而不是安于“j2ee架構師”這個名頭。說到“往上走”和“往下走”之爭,想到兩個不好笑的小笑話。第一個是有天聽到幾個同學談論開發軟件,一個同學說開發mis沒意思,另一個同學就說:“那你去寫匯編啊,寫底層驅動啊,那個有技術含量。”第二個是有次聽武大計算機系某老師說:“java有什么了不起,我用c一樣可以實現多態、繼承。”第一個笑話不加評論。第二個笑話讓我想起以前一直流傳的一句話:“學程序,什么語言都一樣。”個人覺得這句話是帶有很大的誤導成分的。語法層面上,基本的順序、選擇、循環語句是差不多;但要你實際做開發應用呢,你還能說用啥都一樣嗎。不同的語言,設計者在最初設計語言特性時就決定了該語言最有效的應用領域。Ruby之類的動態語言現在大放光彩也是有其理由的。在“向上走”的時候也要注意提醒自己“勿筑高臺于浮沙”。技術無盡的,時間是有限的,要學習什么,學到什么程度,得有清醒的頭腦。

        說到學習技術,決定開始研究Flex了,看了兩天,感覺還不錯。這才是程序員需要的表現層方案,拖放好控件,再編寫用戶交互的script就完了,至于很cool的頁面表現效果的是如何做到的,那是Macromedia的事情。什么struts、webWork之流都是自娛自樂,并不能給用戶帶來多大的使用體驗。JSF想法還不錯,可有多少人支持呢。你說你表現層框架技術再先進,可表現出來的交互界面像yts一樣,對用戶來說還不如回到c/s的懷抱。js的登頂之作也就是Bindows了,還不就那樣。一句話,非常看好Flex!Laszlo也還行,但終究沒有Flex感覺好,而且是開源的,技術支持也沒Flex強。Flex還有一個很好的可視化開發工具——FlexBuilder,大大加快了開發效率。

    posted @ 2005-05-19 09:47 Duran's technical life 閱讀(443) | 評論 (1)編輯 收藏
     
    Suppose we start with a simple <one-to-many> association from Parent to Child.
     1<hibernate-mapping package="org.hibernate.auction.model">
     2 <class name="Parent" table="PARENT">
     3  <id name="id" column="PARENT_ID" type="long">
     4   <generator class="native"></generator>
     5  </id>
     6  <set name="children">
     7   <key column="MY_PARENT_ID" />
     8   <one-to-many class="org.hibernate.auction.model.Child" />
     9  </set>
    10 </class>
    11 <class name="Child" table="CHILD">
    12  <id name="id" column="CHILD_ID" type="long">
    13   <generator class="native"></generator>
    14  </id>
    15  <property name="name" column="NAME" type="string" />
    16 </class>
    17</hibernate-mapping>

    If we were to execute the following code

     1Parent p = new Parent(new HashSet()); 
     2Child c1 = new Child(new String("c1"
    ));
     3

     4try 
    {
     5    session =
     sessionFactory.openSession();            
     6    tx =
     session.beginTransaction();           
     7
        session.save(p);
     8    Long pid =
     p.getId();
     9
        tx.commit();
    10
        session.close();
    11
        
    12    session =
     sessionFactory.openSession();
    13    tx =
     session.beginTransaction();
    14    Parent pp = (Parent) session.load(Parent.class
    , pid); 
    15
        pp.getChildren().add(c1);        
    16
        session.save(c1);
    17
        session.flush();
    18
        tx.commit();
    19

    20}
     catch (HibernateException e) {
    21}

    Hibernate would issue two SQL statements:
    - an INSERT to create the record for c
    - an UPDATE to create the link from p to c

    Hibernate: insert into PARENT values ( )
    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_ from CHILD children0_ where children0_.MY_PARENT_ID=?

    - Hibernate: insert into CHILD (NAME) values (?)
    - Hibernate: update CHILD set MY_PARENT_ID=? where CHILD_ID=?

    This is not only inefficient, but also violates any NOT NULL constraint on the
    MY_PARENT_ID column.

    **********1
    The underlying cause is that the link (the foreign key parent_id) from p to c is not considered part of the state of the Child object and is therefore not created in the INSERT. So the solution is to make the link part of the Child mapping.
    **********1

     <many-to-one name="my_parent"
      class
    ="org.hibernate.auction.model.Parent" column="MY_PARENT_ID"
      not-null
    ="true">
     
    </many-to-one>

    **********2
    Now that the Child entity is managing the state of the link, we tell the collection not to update the link. We use the inverse attribute.
    **********2

     <set name="children" inverse="true">
      
    <key column="MY_PARENT_ID" />
      
    <one-to-many class="org.hibernate.auction.model.Child" />
     
    </set>

    The following code would be used to add a new Child

    1Parent pp = (Parent) session.load(Parent.class, pid); 
    2
    pp.getChildren().add(c1);
    3c1.setMy_parent(pp); //the link is part of the Child object's state. @see***1 

    4session.save(c1);

    And now, only one SQL INSERT would be issued!
    To tighten things up a bit, we could create an addChild() method of Parent.

    1public void addChild(Child c) {
    2  c.setParent(this
    );
    3
      children.add(c);
    4}

    Now, the code to add a Child looks like

    1Parent p = (Parent) session.load(Parent.class, pid);
    2Child c = new
     Child();
    3p.addChild(c);  // 1.let both side of the association knows each other.

    4session.save(c); // 2.save the non-verse side

    =========================================================================================
    CONCLUSION:
    1.The non-inverse(inverse="false") side is responsible to save the in-memory representation (object) to the database .
    --- you should save the child: session.save(c);
    2.Changes made only to the inverse end of the association are not persisted.
    --- you needn't update the parent: //session.update(p);

     1session = sessionFactory.openSession();
     2tx =
     session.beginTransaction();
     3Parent pp = (Parent) session.load(Parent.classnew Long(1
    )); 
     4pp.getChildren().add(c1); //the parent(pp) now knowns about the relationship

     5c1.setMy_parent(pp); //the child(c1) now knows about the relationship
     6

     7//
     when cascade="save-update", update(p) will cause all p's
     8//
     referencing children become persistence(cascade 
     9//
     saveOrUpdate() operation to parent's all children).
    10//
     So, it's same as you explicitly call session.save(c1).
    11

    12//
     when cascade="none"(default), update(p) will just cause
    13//
     p become persistence.
    14//
     And inverse="true", update(p) just persists p, but not 
    15// persists the link between p and c1. @see ***2

    16session.update(pp);  
    17//session.save(c1);  

    18session.flush();
    19
    tx.commit();
    20


    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?

     1session = sessionFactory.openSession();
     2tx =
     session.beginTransaction();
     3Parent pp = (Parent) session.load(Parent.classnew Long(1
    )); 
     4
    pp.getChildren().add(c1);
     5
    c1.setMy_parent(pp);
     6//
    session.update(pp);
     7

     8//
     when save(c1), because c1 holds a reference to its Parent
     9// (my_parent), so p become persistence too.

    10session.save(c1);  //The relationship will be saved. @see ***1
    11session.flush();
    12
    tx.commit();
    13


    Hibernate: select parent0_.PARENT_ID as PARENT_ID0_ from PARENT parent0_ where parent0_.PARENT_ID=?
    Hibernate: select children0_.MY_PARENT_ID as MY_PAREN3___, children0_.CHILD_ID as CHILD_ID__, children0_.CHILD_ID as CHILD_ID0_, children0_.NAME as NAME0_, children0_.MY_PARENT_ID as MY_PAREN3_0_ from CHILD children0_ where children0_.MY_PARENT_ID=?
    Hibernate: insert into CHILD (NAME, MY_PARENT_ID) values (?, ?)


     

    posted @ 2005-05-19 09:28 Duran's technical life 閱讀(583) | 評論 (0)編輯 收藏
    僅列出標題
    共2頁: 上一頁 1 2 
     
    主站蜘蛛池模板: 美女一级毛片免费观看| 亚洲国产成人无码av在线播放| 亚洲暴爽av人人爽日日碰| 国产麻豆视频免费观看| 亚洲黄色片在线观看| 114级毛片免费观看| 亚洲福利视频一区二区三区| 亚洲一级免费视频| 亚洲日本久久一区二区va| 最近免费中文字幕4| 亚洲中文字幕无码久久| 亚洲色图黄色小说| 亚洲高清视频免费| 亚洲首页国产精品丝袜| 免费鲁丝片一级观看| 国产亚洲综合视频| 国产日韩成人亚洲丁香婷婷| 免费国产午夜高清在线视频 | 免费国产精品视频| 一级毛片a免费播放王色| 亚洲VA中文字幕不卡无码| 久久黄色免费网站| 国产一级大片免费看| 成人久久久观看免费毛片| 亚洲国产精品无码av| 欧美a级在线现免费观看| 国产精品亚洲а∨无码播放不卡| 亚洲日本中文字幕一区二区三区| 日韩电影免费观看| 亚洲天堂2017无码中文| 国产福利电影一区二区三区,亚洲国模精品一区 | 88av免费观看入口在线| 伊人久久亚洲综合影院首页| 九月婷婷亚洲综合在线| 亚洲国产片在线观看| 国产成人无码区免费A∨视频网站 国产成人涩涩涩视频在线观看免费 | 亚洲色图激情文学| 国产精品亚洲精品日韩已满| 国产偷国产偷亚洲高清在线| 亚洲国产精彩中文乱码AV| 毛片免费在线播放|