2008年9月25日

          NonUniqueObjectException

          org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

          首先看看這個類:
          //$Id: NonUniqueObjectException.java,v 1.4 2005/02/12 07:19:50 steveebersole Exp $
          2
          package org.hibernate;
          3
          4 import java.io.Serializable JavaDoc;
          5
          6 import org.hibernate.pretty.MessageHelper;
          7
          8 /**
          9  * This exception is thrown when an operation would
          10  * break session-scoped identity. This occurs if the
          11  * user tries to associate two different instances of
          12  * the same Java class with a particular identifier,
          13  * in the scope of a single <tt>Session</tt>.
          14  *
          15  * @author Gavin King
          16  */

          17 public class NonUniqueObjectException extends HibernateException {
          18     private final Serializable JavaDoc identifier;
          19     private final String JavaDoc entityName;
          20
          21     public NonUniqueObjectException(String JavaDoc message, Serializable JavaDoc id, String JavaDoc clazz) {
          22         super(message);
          23         this.entityName = clazz;
          24         this.identifier = id;
          25     }
          26
          27     public NonUniqueObjectException(Serializable JavaDoc id, String JavaDoc clazz) {
          28         this("a different object with the same identifier value was already associated with the session", id, clazz);
          29     }
          30
          31     public Serializable JavaDoc getIdentifier() {
          32         return identifier;
          33     }
          34
          35     public String JavaDoc getMessage() {
          36         return super.getMessage() + ": " +
          37             MessageHelper.infoString(entityName, identifier);
          38     }
          39
          40     public String JavaDoc getEntityName() {
          41         return entityName;
          42     }
          43
          44 }


          解決方案:
               this..getSession().clear();

          posted @ 2008-09-25 17:07 bill 閱讀(902) | 評論 (0)編輯 收藏

          2008年9月9日

          SSH整合中的問題

          Error Creating SessionFactory java.lang.SecurityException: class"org.apache.commons.collections.SequencedHashMap"'異常的解決方案

          本人用 MyEclipse 6.0.0 開發 Struts + Hibernate應用的時候,單獨測試Hibernate的類沒有問題,但是當Web層和Struts整合后,就拋出如下異常:
          %%%%Error Creating SessionFactory %%%% java.lang.SecurityException: class"org.apache.commons.collections.SequencedHashMap"'s signer informationdoes not match signer information of other classes in the same package

             原因是myeclipse  6.0的jar包問題。這個是myeclipse沒有做好嚴格的測試。

             網上好多人說是commons-collectionsXXX.jar的問題。我也不知道。我是把所有的myeclipse生成的jar都remove buildpath 了。
             我又自己添加的jar。就OK!!!!

          posted @ 2008-09-09 21:36 bill 閱讀(233) | 評論 (0)編輯 收藏

          2008年9月7日

          sql server 2000 安裝掛起問題

             sql server 2000 安裝掛起問題:
           解決方案:開始--->運行--->regedit--->HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
             刪除PendingFileRenameOperations

          posted @ 2008-09-07 01:32 bill 閱讀(238) | 評論 (0)編輯 收藏

          2007年12月29日

          JAVA 連接MYSQL

          今天我給大家介紹一下JAVA 連接 MYSQL:
               我都不教你怎么裝MYSQL了,網上我看了很多要下載JDBC我也下載了,和配置了CLASSPATH 但是還是不能用。后來我發現不需要配置了。直接COPY mysql-connector-java-5.0.7-bin.jar
          D:\Program Files\Java\jdk1.6.0_02\jre\lib\ext\mysql-connector-java-5.0.7-bin.jar
          所以,我希望連接的大家不要走彎路。
           這是我寫的程序:

          import java.sql.Connection;
          import java.sql.DriverManager;
          import java.sql.ResultSet;
          import java.sql.Statement;

          public class test {
          public static void main(String[] args) {
          try {
          Class.forName("org.gjt.mm.mysql.Driver").newInstance();
          String url ="jdbc:mysql://localhost/demo?user=root&password=billsxm" ;
          // demo is datebase name
          Connection conn= DriverManager.getConnection(url);
          Statement stmt=conn.createStatement();
          String sql="select * from my_table";
          ResultSet rs=stmt.executeQuery(sql);
          while(rs.next()) {
          System.out.println(rs.getString("name"));
          }
          } catch (Exception e) {
          e.printStackTrace();
          }


          }
          }

          posted @ 2007-12-29 22:38 bill 閱讀(3628) | 評論 (3)編輯 收藏

          僅列出標題  
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(1)

          隨筆分類(2)

          隨筆檔案(4)

          相冊

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 关岭| 西城区| 苍山县| 大同市| 丰县| 海原县| 汉寿县| 扬中市| 防城港市| 大城县| 麻城市| 清新县| 施甸县| 杂多县| 彰化市| 武安市| 和龙市| 新昌县| 南召县| 宝丰县| 鄂伦春自治旗| 台北县| 大足县| 乌审旗| 潼关县| 老河口市| 大连市| 武功县| 秭归县| 玛沁县| 仙游县| 钦州市| 安西县| 云霄县| 沅江市| 丹巴县| 收藏| 花莲市| 平遥县| 敖汉旗| 东宁县|