2007年12月29日

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 阅读(889) | 评论 (0)编辑 收藏

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 阅读(224) | 评论 (0)编辑 收藏

sql server 2000 安装挂起问题

   sql server 2000 安装挂起问题:
 解决方案:开始--->运行--->regedit--->HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager
   删除PendingFileRenameOperations

posted @ 2008-09-07 01:32 bill 阅读(226) | 评论 (0)编辑 收藏

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 阅读(3612) | 评论 (3)编辑 收藏

<2007年12月>
2526272829301
2345678
9101112131415
16171819202122
23242526272829
303112345

导航

统计

常用链接

留言簿(1)

随笔分类(2)

随笔档案(4)

相册

搜索

最新评论

阅读排行榜

评论排行榜