Thursday, April 3, 2008

Hibernate Tips - delete existing item from children

Scenario as below:

I am at a screen now from a web application.

There is a swap-select box on the screen. I select 5 items and click Save button.

Next, the system creates 1 parent object and saves 5 items (selected from screen's swap-select box) as children(a Set) into their parent.

I leave the screen.

Upon next visit to the same screen again, i am trying to remove 2 among the 5 selected items. After that i click Save button.

How should i handle this?

What i need to do is:

1) Get the original Set from the parent object. (Let's name it 'children')

2) At the same time, create new Set(let's name it 'removedChildren'), add those objects that are meant to be removed. (In this case this new Set will have 2 objects)

3) Using removeAll method from Set, put the 'removedChildren' Set in it (children.removeAll(removedChildren))

4) Set the 'children' Set back to the parent. (parent.setChildren(children))

5) Save the parent. (saveOrUpdate(parent))

How to get the last 2 decimal digits using JAVA?

Example:

To get 0.99
from
double abcd =123456789012345.99;

Solution:
double a = 12345678901234.99*100;
String f = Long.toString(((long) a)%100);

Wednesday, March 5, 2008

Very, very much blood shed in KLSE

Over the past few days, KLSE index dropped drastically. A few billions of RM just gone like that. It's like a dagger ripping my heart! Nobody like us (small investors) have ever expected this. Especially right now the general election is approaching!

The profit earned from both stock counters and funds last year soon turned into ashes.

So far, over the 3 stocks i am holding, 2 of them achieve a growth of 46.06% & 46.45% respectively. I have been holding these 2 stocks for 3 years already. It means on average, they have brought >14% profit each year. Well, the other one, which is the only one, causes me losses anyway! It's approaching one year and so far it causes loss at -17.37% ! Well, everything stated here is not the physical one as i have not yet sold the counters off!

Wednesday, January 2, 2008

Development frustration

In this new project, i was using Service Facade design pattern to implement Spring + Hibernate.

I wonder why Hibernate Session is always being closed after the program leaves the DAO level.

I am frustrated when trying to manipulate model/models retrieved from DAO by accessing its/their child/children. It always tells me "Session is closed!"

That's really much different than the way i used to do.

Also, i could not manipulate Hibernate Transaction across different calls of services. I could not control when and where to commit or rollback just like what i usually do!

The Common Control also makes me scratching my head a lot! I am still in the process of getting familiar with it. I am now missing much on the traditional Struts + Javascript technique. Anyway, pros and cons always there.

Today bad news came, so, end of this month, have to complete everything! Yeah, another mission impossible!

One sicked, one blinded, one cursed

How can you expect the project to be completed?

Tuesday, January 1, 2008

喜迎元旦, Happy New Year!

2008元旦至。回顾2007年,悲多于喜,确是不堪回首。

1)事业-停滞不前、碰到瓶颈。
2)爱情-平平淡淡、冷战频频。
3)友情-三五知己、冷冷清清。
4)亲情-父亲仙逝、面具卸去。
5)钱财-基金不俗、股市丰收。
6)休闲-毕览好戏、柬蒲赛游。
7)健康-睡眠不足、病痛频仍。

为新的一年许下新的愿望。

1)事业-自行创业、转大机构壮大基金、遍寻良机。
2)爱情-加额时间、加倍关怀、增添元素、双游天下。
3)友情-广结善缘、慎选活动、慷慨解囊、笑口常开。
4)亲情-倍孝家慈熏陶家妹
5)钱财-善理基金股市续旺
6)休闲-毕阅好书、毕览好戏、毕听好乐、美国之旅?中国之旅?。
7)健康-睡眠充足大病必除定期运动避免破食
8)学业-升阳证书、会计课程、财经硕士、风水处成、乐理初读。

进行中:
1)大病必除

Looking back to year 2007, it is a kind of disastrous year for me...

My career remains stagnant. It seems like i can't grow further. I am afraid of this feeling. I had been looking for the reason and found out that my personality is the one that actually restricts myself a lot. Hence I wish could have a total change of environment so that i could start everything new! I resigned. However i was persuaded by my technical director to give myself a chance again at Melaka branch. Now, i am at Melaka branch. I don't feel happier. Even tough it is much more relax than the previous office. Most probably, is due to there are still people i know is here... i have been trying to turn myself another person. However, the tight deadline has once again put me into a bad situation. I ask myself, do i still want to continue this kind of tension life? Take over my dad's business? As a full time freelancer? Join any MNC in the Klang Valley area? I have a dream, that is to be sent to oversea for training. I believe if i weren't to join the current company last time, i would have already been going oversea either for mission or for training for a few times already. I expect the coming job suits my personality, which is patient and less-communicative. I hope my career will be more towards R&D.

On a full 'Yin' day, my dad had passed away. What could be worst than this? Sadly,during the course of seven '7' week, i did not dream of him at all. My sister dreamed of him during his first '7' week. He was in a wonderland, bringing us the whole family to play around. He was happy according to my sister, he in the end hid inside a leave. What does that mean? I hope the answer is positive. I really really hope dad is there. Whoever out there, can YOU give me the answer?
I couldn't forget the moment. My teardrops could not stop falling while i was cleaning his body. Everything is so stiff, and so cold, blood still in his mouth. Dad, i know you did not want to leave, yet the thing turned out this way. What could me, as a son, as a human, do? Sorry for not always being obedient to you, i actually do remember your advises. They are the treasures that you passed to me. They are priceless.

The funds i bought continue to generate good number of income for me. Of course, it shall not be counted as i did not actually sell them. The achievement i am proud of is, i have helped one of my customers to achieve a 30%++ growth in exactly one year time. When he sold the fund, i could feel his excitement! I was so happy for him too! Imagine, let's say one year ago you invested 10k, right now you will get 13k! Don't you get excited? In the coming years, i expect i will invest in more funds, i wish i will choose the right one every time! Same goes for stock market! I am holding a few, i plan to sell one of them which is less stable in the coming future. The rest of the stocks remain lucrative. Loving them...!

I started to lose my health since few years ago. I think that was due to insufficient rest. There are a few sicknesses keep haunting me. There are 3 major ones. I am now trying to get them cured one by one in the coming year. I could not afford to risk my health anymore. My mom and sister need me!

I was thinking about to join US Summer Camp in year 2008. Right now my dad has passed away, do i still need to persist my dream? In fact, i was in the progress of finding suitable camp to join! Now, bad events had passed, shall i be selfish to get away from my family for 3-6 months? They are worried i could not live well over there...

MBA in Finance, shall i continue to pursue this? I really hope to gain more financial knowledge by taking a master. However, one of my friends suggested me to take ACCA instead. How funny? I am considering this option anyway. MBA, the university that offers this course is quite near to the place i stay. However the price is expensive. I would rather take a foreign U one. The best is to go oversea to study! I think i will start looking for scholarship. Again, shall i just leave my mom and sis like that? i guess the answer is, no way! Perhaps i will consider taking a distant leaning MBA programme.

SCJP, oh my god. It's already 2008. I think my ticket is going to expire soon. I really got to move forward asap!

Monday, October 29, 2007

父亲,就这样走了

就这样。。。走了。

留下的,只是子女们未克献尽孝心的痛苦。

每个星期六,当我还在回家的路途中,父亲往往是第一个致电过来的。

每一次,我都觉得不耐烦,觉得自己会没事安全到家的。可是,我忘了父亲他其实是在关心着我的,这是他给我的无形的爱。

我与父亲向来缺乏沟通,最近几年稍有起色唯亦不足。多的是他的万般叮咛,“早睡、早起”。

他离去之前,我都没好好的遵循他的话。

如今,人都没了,我心悲痛。尤其是替父亲尸身梳洗的那一刻,接触的是冰冷的肌肤!梳洗当儿血还从口流出!他全身发黄,双手五指往内紧收!父亲,我知你不愿就此离去,孩儿实在心如刀割,因无法扭转眼前的残酷事实!孩儿只能可望上天恩赐奇迹啊!而奇迹,又往往是非常的遥远!

前一晚,我在匆忙的归途中,心里还以为只是小事一桩,送院后经过调理该无大碍,怎知竟是与父亲永别之时!

家里血迹斑斑,那味道闻之欲呕!我保持镇静与母亲尽快的处理血迹。不久医院电话急响,心里不祥之感涌现,急忙压下不作他想。电话中,护士催促我们尽快回到医院,医生有重大事情欲与我们讨论。此时已是凌晨一时多,重阳日已过,接下来的卦乃全阴之卦!我父乃注定丧命于今日?

“没办法了,没办法了”,这样的答案从医生口中出来,真让人绝望!我拼命的联络各地医院,无奈各方借故推搪。好不容易有一位医生肯收我父亲,天大喜讯啊!可是,天,您为何不给父亲多几个小时???为何偏在此时夺走了他的性命???

看着血不停的从父亲鼻中喷出,我感到绝望、无助、茫然。。。

医生拉上了布与护士作最后的抢救,我与母亲之能期待阿弥陀佛之力搭救父亲。我闭上了眼睛,念着阿弥陀佛,千丝万缕涌上心头。。。

临时抱佛脚。。。

在那一个全阴卦的星期六的凌晨三时许,母亲抱着父亲的尸身痛哭。。。而我亦在父亲耳边作最后的呼唤。

他,不会醒来了。父子缘尽今世。

Wednesday, October 10, 2007

新环境,新体验,新心情

道,是怎么样的?

新环境,带来了一些的不确定的元素。

虽然,个个都是熟悉的面孔,然而毕竟前车可鉴,吾杯弓蛇影,最惧不知此蛇乃蛇乎?!

项目,不可能的任务,然而为了明年的打算,苦咬牙关,即使举步维艰仍得踏刃而走。

家里,需费时适应,培养新习惯,还不知可行否。

明年将至,吾仍在混沌矣!创业?国际公司?硕士?资讯工艺?财经?

我仍在努力弄清一切,战战兢兢的拨开一切云雾,寻找埋没在黑暗中地平坦道路。