Anything that interests me finds place here. Software dominates my interests and hence a good part of this blog as well.
Friday, September 04, 2009
Hibernate Getting Started
Hibernate Getting Started
Hibernate Mapping File - Specifies how instances of persistent classes are to be persisted and loaded. This specification is laid out by detailing the properties that are mapped to columns, classes that are mapped to tables and the relationship between classes mapped in DB semantics like foreign keys (and join tables?).
Basic Hibernate Mapping File (there are multiple listings of the same file. Each listing builds upon the previous listing):
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- This file will first be looked up in classpath, then on the web. -->
<hibernate-mapping package="org.hibernate.tutorial.domain">
[...]
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<!-- All classes that represent persistent entities, must be mapped to a table -->
<!-- This tells hibernate to persist and load instances of Event class to the EVENTS table. Each instance of Event is a row in EVENTS table -->
</class>
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<!-- The class Event bean has a property (or getter and setter) by name "id" that serves as a key or id of Event class. The id has to be stored to the column EVENT_ID. -->
<generator class="native"/>
<!-- Use hibernate's key generation strategy (How are identifier values generated?) to generate the Keys for Events. Other strategies include Data base generated keys, Globally unique keys, application generated keys -->
</id>
</class>
</hibernate-mapping>
<hibernate-mapping package="org.hibernate.tutorial.domain">
<class name="Event" table="EVENTS">
<id name="id" column="EVENT_ID">
<generator class="native"/>
</id>
<!-- Other properties of Event class. If a property is not mapped, it is not considered persistent. -->
<property name="date" type="timestamp" column="EVENT_DATE"/>
<!-- Event has a getDate() and setDate() and the value is to be stored in the column named EVENT_DATE. Type is hibernate mapping type. There are converters that convert between Java to SQL data types and visa-versa. If type not specified, hibernate will try to determine the mapping type and conversion type. This automatically (detected through reflection - can impact start up performance) type may not be what you want. For example java.util.Date can map to "date" (only date e.g. July 4th, 2009), "timestamp" (both date and time e.g. July 4th, 2009 10:00:00 HRS) or "time" (only time e.g. 10:00:00 HRS). Then you explictly specify the type -->
<property name="title"/>
<!-- Event has a getTitle() and setTitle(). Column name is not specified, so use the property name as the column name. -->
</class>
</hibernate-mapping>
Attitude, to me is more important than facts, education, money, circumstances, failures, successes and what others think and say
“The longer I live, the more I realize the impact of attitude on life. Attitude, to me is more important than facts. It is more important than the past, than education, than money, than circumstances, than failures, than successes, than what other people think or say or do. It is more important than appearance, giftedness or skill. It will make or break a company …a church …a home. The remarkable thing is we have a choice everyday regarding the attitude we will embrace for that day. We cannot change our past …we cannot change the fact that people will act in a certain way. We cannot change the inevitable. The only thing we can do is play on the one string we have, and that is our attitude. I am convinced that life is 10% what happens to me and 90% how I react to it. And so it is with you. We are in charge of our attitudes.”
- Charles Swindoll through Julie911
Thursday, September 03, 2009
Logic that needs to be executed only in the JSF Render Response Phase
if (FacesContext.getCurrentInstance().getRenderResponse()) {
// Logic that needs to be executed only in the JSF Render Response Phase} Source - balusc Have you found joy in your life? 'Has your life brought joy to others?
“You know, the ancient Egyptians had a beautiful belief about death. When their souls got to the entrance to heaven, the guards asked two questions. Their answers determined whether they were able to enter or not. ‘Have you found joy in your life?’ ‘Has your life brought joy to others?’”
- The Bucket List through Julie911
Wednesday, September 02, 2009
Look around you - played in Lost
Look down the bar from you
The lonely faces that you see
Are you sure that this is where you want to be
These are your friends
But are they real friends
Do they love you the same as me
Are you sure that this is where you want to be
You seem in such a hurry to live this kind of life
You've caused so many pain and misery
Look around you, take a good look
And tell me what you see
Are you sure that this is where you want to be
Don't let my tears persuade you, I had hoped I wouldn't cry
But lately, teardrops seem a part of me
Oh, look around you, take a good look
At all the local used-to-be's
Are you sure that this is where you want to be
Willie Nelson
Tree conflicts
Nice discussion here:
http://blogs.open.collab.net/svn/2009/03/subversion-160-and-tree-conflicts.html
Friday, August 28, 2009
Medicare
Part A - in patient services. This is free as it is paid for through medicare taxes when one worked.
Part B - out patient and other medical expenses - need to pay a premium ($96.40 in 2008)
media multitasking v. task multitasking
Our abilities, frailties and virtues
— Sydney J. Harris through julie911
Thursday, August 27, 2009
Nice trick with xargs
ls | xargs -t -I{} echo {} {}.new
-t echo the command that is going to get executed before executing
-I{} Insert a new line where{} appears
e.g.
$ ls
first.txt second.txt
$ ls | xargs -t -I{} echo {} {}.new
echo first.txt first.txt.new
first.txt first.txt.new
echo second.txt second.txt.new
second.txt second.txt.new
Building a massive system is like building a simple API - Eric
In response to Steve indicating that Eric is pretty good at building big systems from the scratch
Top grade schools in chennai
From here : http://www.indusladies.com/forums/schools/4665-age-criteria-admission-lkg-chennai.html
PSBB, DAV, chettinad vidhyasharm, State Bank of India Officers Association (SBOA) school, Vidya mandir, PS senior
Schooling for kids in Chennai
Nice thoughts from http://goodschoolsofchennai.blogspot.com/
1. Identifying the right skill and potential in the kid
2. Identify what interests the child.
3. Get your aspirations in line with what the Kids interest is.
4. Understand what needs to be provided to the kid to thrive on his interest.
5. Providing the right environment at home, school and the places that we visit regularly to inspire them to pursue their interest.
6. Providing the tools for them to nurture their talent.
7. Giving the quality time and feedback for them to improve.
8. Providing the freedom for them to express their point of views.
Wednesday, August 26, 2009
God is behind me - My father
When we came across a pretty helpful Delta airways staff while checking in the baggage at
Monday, August 24, 2009
Breathe
If you feel stressed out and overwhelmed, breathe. It will calm you and release the tensions.
If you are worried about something coming up, or caught up in something that already happened, breathe. It will bring you back to the present.
If you are discouraged and have forgotten your purpose in life, breathe. It will remind you about how precious life is, and that each breath in this life is a gift you need to appreciate. Make the most of this gift.
If you have too many tasks to do, or are scattered during your workday, breathe. It will help bring you into focus, to concentrate on the most important task you need to be focusing on right now.
If you are spending time with someone you love, breathe. It will allow you to be present with that person, rather than thinking about work or other things you need to do.
If you are exercising, breathe. It will help you enjoy the exercise, and therefore stick with it for longer.
If you are moving too fast, breathe. It will remind you to slow down, and enjoy life more.
So breathe. And enjoy each moment of this life. They’re too fleeting and few to waste.
By Leo Babauta through Julie911
Friday, August 21, 2009
Wednesday, August 19, 2009
Hope, Confidence and Optimism - Julie911
Hope: A feeling of expectation and desire for a certain thing to happen.
Confidence: A feeling of self-assurance arising from one’s appreciation of one’s own abilities or qualities.
Optimism: Hopefulness and confidence about the future or the successful outcome of something.
Tuesday, August 18, 2009
a alternative loop-up table
In the above case, we had a special column for Key. Instead we could also have a code for the course like this:
| Student Table | | |
| Id | Name | Course |
| 1 | Abc | Comp |
| 2 | Xyz | Art |
| Course table | |
| Id | Name |
| Comp | Computers |
| Art | Arts |
This way the code is more readable. The downside is its pretty difficult to change the i.d. If in the future its required to change the id of “computers” course from “comp” to “it”, then that is not a easy deal.
Lookup tables
| Student Table | | |
| Id | Name | Course |
| 1 | Abc | 100 |
| 2 | Xyz | 101 |
| Course table | |
| Id | Name |
| 100 | Computers |
| 101 | Arts |
In the above case the Course table is a lookup table. You look up with the course id and get the course name
Friday, August 14, 2009
Unit tests are faster
Write unit tests and your functionality gets done faster and most reliable.
Thursday, August 13, 2009
Clear history of firefox before seeing changes made to css files
Firefox caches css files. So if you change a css file, it may still be using the old css file and your changes will not be seen. So clear the cache to see the changes take effect.
Wednesday, August 12, 2009
Oracle putting its acquired companies to work
It uses JD Edward’s EnterpriseOne as a single point of management for its applications, BEA system’s web logic (integrated with Oracle’s home grown variant) as OFM (Oracle Fusion Middleware) along with its all famous DBMS to offer a full stack of software (added with OFA [Oracle Fusion Application] which are pre-packed applications that leverage on OFM and the DBMS.
Tuesday, August 11, 2009
Take a day off. If you have something planned for tomorrow that you are not looking forward to, try to cancel or postpone it. When avoiding your regular is impossible, plan ahead for a weekend or a day off by making your “tomorrow” a few days later than the next day.
Do something that you love. Spend some time with a favored activity, even if it is something that you have not done for a while.
Invite a friend or loved one to visit you. Have lunch with them, or watch a movie you both enjoy. Having a friend or loved one around can lift your spirits and make you feel good.
Eat healthy foods. Eating right will make your body feel better. That’s not to say that you can’t have your favourite foods, but make sure to incorporate fruits and veggies into your diet.
Think positively. Wake up and realize what an awesome day it is and how awesome you are!
Listen to a fast upbeat song, such as Jump or Tarzan Boy. It will put you in a good mood.
Seize the moment. Time is fleeting and there is nothing worse than a missed opportunity. Go for it!
Do something everyday that scares you! It helps you grow as a person, and makes you feel great afterwards! But don’t do something dangerous.
Saturday, August 08, 2009
Nice lines by ryan adams
It’s like you’re just dreaming of busting someone else
Hands they hold a candle to the pages
These days they go so fast
These days are ours
Follow the lights that line the streets
connecting telephones
Follow the lights from house to house
And they will lead you home
They will lead you home
Cause there was never anywhere to go
There was never anywhere to go
But home
If every second year is true
Our love is strong enough to guide the way we walk through
Hands inside of hands
Hearts inside of hearts
Like eyes closed
Side by side and through
Follow the lights that line the streets
connecting telephones
Follow the lights from house to house
And they will lead you home
They will lead you home
Cause there was never anywhere to go
There was never anywhere to go
But home
If everything we are is true
Our memories are attics in those houses on the hill
Our love is there above us holding everything so still
And we are always here
Yes we are always here
So follow the lights that line the streets
connecting telephones
Follow the lights from house to house
And they will lead you home
They will lead you home
Cause there was never anywhere to go
There was never anywhere to go
There was never anywhere to go
But home, home
Friday, August 07, 2009
Listen to the sound of your breath, then relax it
- Listen to your life with your eyes closed
- Listen to your words before you speak them
- Listen to what you want - more of - in life
- Listen to the sound of your breath, then relax it
- Listen to your intuition. It’s always trying to grab your attention
- Listen to what your body needs, right now. Put your thumbs in your ears, cover your eyes with your fingers and then listen
- Listen thankfully to the sounds of nature
- Listen for the wisdom in your problems
- Listen more, talk less
- Listen to your thoughts in slow motion. Are they bringing you closer to your dreams or taking you further away?
- Listen to your life without the sound of technology and machines (no phone, TV, ipod etc)
- Listen to silence
- Listen to your favourite music
- Listen, really listen to your children, family and friends
- Listen to how many sounds are actually happening around you right now
- Listen to the calming sounds of the ocean by cupping your hands over your ears and turning your awareness inwards
- Listen to the sound of your favourite food cooking
- Listen to your heart - What is it saying?
- Listen to the sound of your feet when walking
- Listen to the appreciation of your body after eating something healthy
- thehealthylivinglounge.com
Wednesday, August 05, 2009
Conciousness during the persuit of a big goal
Aiming high is good. Big goals are good. But when it comes to pursuit, small goals (that match your skill and challenge) must occupy your consciousness. Small goals have smaller sacrifices (like spending your time studying instead of watch your favorite TV show). Smaller sacrifices are within one’s skill/ability. Successful small sacrifices, gives one the confidence that the goal is achievable.
It is within one’s ability to be mindful of one’s smaller goal and be focused on putting effort towards the goal by seeing small efforts giving small results. These small results put together will one day look like the big goal that one set out to achieve.
Heaven and hell here in earth
Heaven and hell is not something that one experiences after death. It is something that is undergone or experienced here in earth. God doesn’t sit in heaven and decide if you are going to heaven or hell after you die. He sites in your conscience and delivers heaven or hell based on virtues and non-virtues that occupy your consciousness.
Virtues like honesty, love, forgiveness allow you to experience heaven manifesting as peace in each moment on earth. Non-virtues like cheating, egotism, anger take you into hell experienced as a heavy feeling or guilt.
-me
ISO Sensitivity in digital cameras
ISO Sensitivity controls the amount of light that gets captured for photos taken. This is the same as the exposure rate in analog/film based cameras. In analog cameras the amount of light captured in the film is controlled by the duration of time the shutter is open for one click (exposure rate). In digital cameras, this is controlled by setting the ISO Sensitivity level of the cells that capture the incoming light upon click.
During bright light conditions, a lower ISO sensitivity is preferred and a higher sensitivity in dark conditions.
Tuesday, August 04, 2009
One brut way to find the cause of a regression change
Lets say we have N number of committed changes. A new defect surfaces. One brut way to find the cause of the defect is to revert the code to the point where the most dubious code change and see if the defect still arises. If it does, the most dubious code change or one of its successive commits are the culprits. If not, the most dubious code change is not the culprit.
Saturday, August 01, 2009
Truth and honesty are the foundation in any relationship
Friday, July 31, 2009
It is the fool who fails to return to the place of his last happiness
Monday, July 27, 2009
Wednesday, July 22, 2009
Multilayer validation strategy
The validation logic of an application can be spread across the application. Some logic against the UI, some against Business layer, some against service layer and some against DAO layer.
Sunday, July 19, 2009
One difference between chapter 7 vs. 11 bankruptsy
Chapter 11 - Trying to re-habilitate
Wednesday, July 15, 2009
Simple APIs responsibilities on arguments
public Student createStudent(Student student, Couse course)
Lets say the responsibility of this API is to save the student and return the saved version back (the saved version will have the key).
Some implications of this API is that
- If there is a failure, student and course objects should be left un-touched. If there were changes made before the createStudent() failed, all those changes should not be visible to the client of this API. This can be done by taking a copy of the student and course and letting createStudent() operate on that copy. That way if there is a failure, then the original student and course object remain intact.
- If the operation succeeds, the client of this APIs would usually require that all changes made by createStudent() be reflected in student and course. To achieve this, after all createStudent operations complete successfully, overwrite the copy that was made at that start of the call back into student and course.
Saturday, July 11, 2009
Saturday, July 04, 2009
Do what you can do
My hapiness and self worth
- Stacey Charter
Time it takes to get something done
- Earl Nightingale
HQL notes
Case IN-sensitive
- Doubt: "This manual uses lowercase HQL keywords. Some users find queries with uppercase keywords more readable, but this convention is unsuitable for queries embedded in Java code." - why is this so?
the from clause
- from Student as student, Department as department gives a cartesian product of all students and all departments.
- inner join - returns a row when there is a match in both the tables
- left outer join - returns all rows from the left table even if there are no matches on the right table
- right outer join - returns all rows from the right table even if there are no matches on the left table
- full join - returns rows when there is a match in one of the tables
| emp_no | emp_name | dept_no |
| 1 | xyz | 1 |
| 2 | abc | 2 |
| 3 | ghi | 4 |
| dept_no | dept_name |
| 1 | IT |
| 2 | Sales |
| 3 | Accounts |
| emp_no | emp_name | dept_name |
| 1 | xyz | IT |
| 2 | abc | Sales |
| emp_no | emp_name | dept_name |
| 1 | xyz | IT |
| 2 | abc | Sales |
| 3 | ghi |
| emp_no | emp_name | dept_name |
| 1 | xyz | IT |
| 2 | abc | Sales |
| Accounts |
| emp_no | emp_name | dept_name |
| 1 | xyz | IT |
| 2 | abc | Sales |
| 3 | ghi | |
| Accounts |
HQL Joins
Tuesday, June 23, 2009
Cities hosting I.T Companies in the U.S
-
-
-
-
- Bay Area
-
- Massachusetts
Sunday, June 21, 2009
Command Design Pattern
Following is a class diagram of various entities:

invoker - the object that needs to make the request without knowing receiever
Command - the interface that specifies the APIs that Command implementations must realize/implement.
CommandImpl - A implementation of Command that contains logic to realize command. Usually delegates to a receiver.
Receiver - Object that contains the actual business logic to realize the request. This usually has no web or struts context.
For example the struts framework must invoke application logic without knowing which application object is receiving the request or what operation is being performed by the application object. To achieve this, struts exposes Action interface. Application action classes must implement the struts action interface. The responsibility of the struts action implementation is to realize the business functionality. To do so, the action implementation usually invoke a application object (a pure business object that has no dependency on struts or has not web context). This application object, in the context of Command Design Pattern, is referred to as a receiver.
The struts ActionServlet handles the in-bound request and invokes RequestProcessor.process method. This method as part of the many things it does, has a reference to an Action implementation (specified in struts-config.xml) and invokes Action.execute(ActionMapping, ActionForm, HttpServletRequest, HttpServletResponse) without knowing which action implementation it is invoking or the operation it is performing..
The Action interface is a good example of Command component in Command design pattern.

Struts classes: Source
Saturday, June 20, 2009
Drools basics
What is a Rules Engine?
If you've ever taken a series of conditional statements, tried to evaluate the combinations, and found yourself writing deep nested logic to solve a problem, these are just the sorts of entanglements that a rule engine can help you unrave.
Complex business rules when expressed as rules are easier to understand.
What is a business rule?
Its a business-oriented statement that encompasses a business decision. Often implemented by a if-then statement.
e.g.
Given a car and a driver, if all of the following conditions are met:
The car is red
The car is in a sport class
The driver is male
The driver is between the ages of 16-25
The consequence is a 20% insurance premium increase.
These business rules are not new: they are the business logic that is the core of many business software applications. If you're a developer, you've seen these rules time and again expressed as a subset of requirements. They're statements like "give a twenty-percent discount on orders over three items on Mondays" or "we don't insure sixteen-year-old males on supersport motorcycles."
The difference is in how the rules are implemented in the code. Traditionally these rules are written as if-else statements in application code. In drools, these rules are specified in Business rules form.
A rules engine takes these rules and executes them. Apart from that the engine also facilitates creation, deployment, storage, versioning and other administrative functions on rules.
Given a set of rules, the rules engine needs to determine whether a given rule should be selected for execution or not. Once selected for execution, the engine needs to determine the order in the selected rules must be executed in.
The rules engine uses a matching algorithm to determine which rules to execute. Drools uses a matching algorithm called Rete. Rete constructs a tree of business rules. Each node is a rule. Each leaf in the rules tree is a rule consequence (e.g. increase premium by 20%). A Fact (an applicant of age 21 applied for insurance for a green sedan [a 4 door car]) enters the top of the fact tree. Based on whether or not the fact satisfies a rule in a node, the fact navigates through the tree until it hits a leaf or a rule consequence. Treat, Leaps, Rete II and Rete III are improvisations of Rete.
Rules engines make sense when there is a certain level of complexity in the rules. If the rules are trivial or if every rule has to be run on every fact, then the overhead of using the rules engine may not be necessary. If the rules are complex, then the overhead makes sense.
Different rule engines expect rules to be specified in different ways. In java drools rules can be specified in xml files or java annotations or java POJOs that are wired with spring.
an example drools 3.0 .drl file:
package com.insurance.auto
import com.insurance.auto.Driver
import com.insurance.auto.Car
import com.insurance.auto.Policy
import com.insurance.auto.Style
import com.insurance.auto.Color
import com.insurance.auto.Percentage;
rule "High Risk"
when
Driver( male=true, age >= 16, age <= 25 )
Car ( style == Style.SPORT, color==Color.RED )
$p: Policy ()
then
$p.increasePremium( new Percentage( 20 ) );
Flavors:
The rule server can be embedded or can run as a server. If the application using the rules is already in a distributed env. (like EJB, web services, corba etc..) then hosting the rules in a server is better otherwise embedded mode is good.
Tuesday, June 16, 2009
Logging call stack
There may be situations where in you only want to log the call stack (to find out how a method got invoked). An easy way to do this is to throw a new java.lang.Exception(“”). Catch it and log it in the log file. This way you can have the call stack for a method invocation without having the bebug.
try
{
throw new java.lang.Exception("Dummy exception to display call stack");
} catch (java.lang.Exception e)
{
log.debug("stack trace", e); // This will print the exception on to the log file
}
Wednesday, June 10, 2009
Using commons bean library to get all properties of a bean
public String[] getFieldValues( DataObject bean )
{
List<String> fieldValues = new ArrayList<String>();
try
{
// TBD: handle null key
fieldValues.add(PropertyUtils
.getSimpleProperty(bean, "key")
.toString());
PropertyDescriptor[] properties =
PropertyUtils.getPropertyDescriptors(bean);
for (PropertyDescriptor property : properties)
{
String propertyName = property.getName();
Object propertyValue =
PropertyUtils.getSimpleProperty(bean, propertyName);
if (null != propertyValue
&& !propertyValue.toString().isEmpty())
{
fieldValues.add(propertyValue.toString());
}
}
}
catch (Exception ite)
{
// TBD: handle this
}
return fieldValues.toArray(new String[0]);
}
Friday, June 05, 2009
Commons lang StringUtils
public static boolean isBlank(String str) will return true if str is null or trimmed str is “”Thursday, June 04, 2009
What is GWT (Google Web Toolkit)
You write in java and GWT compiles to javascript. Different dialects for each browser generated.
Used to write rich client applications like think client applications. GWT is a client side. Had remote procedure calls to made server side calls. On server side
JSF and other web framework support GWT. So GWT can be used to make
Put the pedal to the metal (use a tech. to achieve traction). :-)