2008年7月26日 星期六

hibernate LazyInitializationException

hibernate 3 預設有啟動LazyInitialization
在Session.
load(Class theClass,Serializable id)時
還不會將資料庫中的資料載入到物件中,一直要到物件屬性被改變時才會載入,
但修改物件時Session必須處於open狀態,否則會丟出LazyInitializationException
如果在Session關閉後才要使用物件則可以使用Hibernate.initialize(rec_obj);
來先行載入資料庫的資料到物件中
如:
Session session = HibernateUtil.getSessionFactory().openSession();
User user = (User) session.load(User.class, new Integer(1));
Hibernate.initialize(user);

session.close();

Hibernate的Session物件有兩個:
org.hibernate.Session 及 org.hibernate.classic.Session
classic版是為了相容於Hibernate 2.x的物件,已半棄用,建議新的開發要使用
org.hibernate.Session

使用Hql進行查詢時可以一次查詢多個資料表的物件,只要把資料TO物件extends/implements同一個class/interface即可,如:
Man implements Human ...
Woman implements Human ...
同時查找Man 及 Woman的資料:
Session.find("from Human ...");

透過ThreadLocal讓多個Thread各自管理自己的Session物件範例:
public class HibernateUtil {
public static final SessionFactory sessionFactory;
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() throws HibernateException {
Session s = session.get();
if(s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = session.get();
if(s != null) {
s.close();
}
session.set(null);
}
}

2008年7月22日 星期二

debian下使用zhcon

沒有做任何設定直接執行zhcon會造成畫面錯亂當機的情型
只要在/boot/grub/menu.list檔案的最下面的kernel字串後加上vga=791再重新開機就可以了

title Debian GNU/Linux, kernel 2.6.18-4-k7
root (hd0,0)
kernel /boot/vmlinuz-2.6.18-4-k7 root=/dev/hdd1 ro vga=791
initrd /boot/initrd.img-2.6.18-4-k7
savedefault

vga其他顯示模示代碼如下:
Screen 640x480 800x600 1024x768 1280x1024 1600x1200
Colors --------------------------- -------------------------------------------
256 | 769 771 773 775 796
32,768 | 784 787 790 793 797
65,536 | 785 788 791 794 798
16.8M | 786 789 792 795 799

2008年7月21日 星期一

virtualbox

下載:
http://www.virtualbox.org/wiki/Downloads

安裝:
#dpkg --install virtualbox_1.6.2-31466_Debian_etch_i386.deb

加入群組:
#usermod -G vboxusers -a muchu1983

設定Host key:
檔案 -> 偏好設定 -> 輸入

複製一份.vdi硬體檔:
VBoxManage clonevdi /mnt/hdb1/debian-vbox.vdi /mnt/hdb1/debian-vbox-v2.vdi
複製完成即可再建立一台新的虛擬機來使用新的硬碟檔

虛擬機之間的網路互通:
啟用虛擬機的新網卡eth1並設定為掛附到內部網路及給定相同的network name
再分別設定各別虛擬機的eth1 ip (例:192.168.1.100 & 192.168.1.200)
#ifconfig eth1 192.168.1.100

主端分享資料夾給客端電腦:
需先安裝客端額外功能 -
#sh /media/cdrom0/VboxLinuxAdditions.run
在主端vbox程式的 設定值 -> 分享資料夾 -> 加入新的分享資料夾
啟動客端電腦,mount 分享資料夾
#mount -t vboxsf share /mnt/share

2008年7月12日 星期六

java Thread wait() notify() notifyAll() 運作

.使用wait()、notify()、notifyAll()方法前,執行緒必需先獲得物
件鎖,也就是說,執行緒必需是處理物件的synchronized區段
中,該執行緒是處於Running狀態的。

.當執行緒在物件的synchronized區段中碰到了wait()方法,該執
行緒就必需釋放出該物件的Lock,並進入該物件的wait pool中
等待。

.執行的過程式可能會有多個執行緒因為碰到wait()方法而在wait
pool中等待。

..此時。如果某個使用該物件的執行緒碰到了notify()方法,那麼在
物件的wait pool中第一個碰到了wait()方法的執行緒就會被移到該
物件的lock pool中繼續等待取得物件鎖。

..而如果某個使用該物件的執行緒碰到了notifyAll()方法,那麼在物
件的wait pool中所有的執行緒就會被移到該物件的lock pool中,
而優先權最高的執行緒會先取得物件鎖。

2008年7月8日 星期二

Jaas Login module flag意義

      1) Required     - The LoginModule is required to succeed.
If it succeeds or fails, authentication still continues
to proceed down the LoginModule list.

此LoginModule一定要驗証成功整個Login程序才會通過,無論驗証成敗,均會繼續
進行下一個LoginModule驗証。

2) Requisite - The LoginModule is required to succeed.
If it succeeds, authentication continues down the
LoginModule list. If it fails,
control immediately returns to the application
(authentication does not proceed down the
LoginModule list).

此LoginModule一定要驗証成功整個Login程序才會通過,驗証成功,則繼續進行
下一個LoginModule驗証,若驗証失敗,則不繼續進行下一個LoginModule驗証,
驗証程式完成。
3) Sufficient - The LoginModule is not required to
succeed. If it does succeed, control immediately
returns to the application (authentication does not
proceed down the LoginModule list).
If it fails, authentication continues down the
LoginModule list.
此LoginModule不一定要驗証成功,若驗証成功,則繼續進行則不繼續進行下一個
LoginModule驗証,若驗証失敗,則繼續進行下一個LoginModule驗証,
4) Optional - The LoginModule is not required to
succeed. If it succeeds or fails,
authentication still continues to proceed down the
LoginModule list.
此LoginModule不一定要驗証成功,無論驗証成敗,均會進行下一個LoginModule驗証。

2008年7月6日 星期日

XFce4快捷鍵記錄檔位置

XFce4 的預設快捷鍵位置在
/usr/share/themes/Default/xfwm4/keythemerc