JPA Composite Primary Key

Here is an example of a composite primary key object for Hibernate/ JPA. It makes things more complicated by creating a relation from one of the pk fields to another entity. If we didn’t have this extra relation then the inner class would have another simple @Column instead.

@Table(name="MY_TABLE" )
public class Test implements Serializable, Validatable
	public Test(){}

	PK id;

        //other fields
	public static class PK implements Serializable{
		public PK (){}
		@Column (name="PK_1")
		private Long pk1;
		private AnotherEntity ent;

		public boolean equals(Object obj) {
	        if (obj == this) return true;
	        if (obj == null) return false;
	        if (!(obj instanceof PK )) return false;
	        PK pk = (PK) obj;
	        if (pk.ent == null && pk.pk1 == null) return false;
	        return new EqualsBuilder().append(pk1, pk.pk1).append( ent, pk.ent).isEquals();

	    public int hashCode() {
	    	return new HashCodeBuilder().append(pk1).append(ent).toHashCode(); 




Canada vs Australia!

We had a short trip to Canada in Jan 2012 and in addition to having a break we wanted to compare it with Australia for living. The following is solely my own opinion so others may think otherwise! In the comparison I was mostly having Sydney and Toronto in mind.

Things cheaper in Canada:

  1. Property
  2. Food
  3. Clothes
  4. Labour
  5. Gas

Thing cheaper in Australia:

  1. Mobile plans
  2. Car insurance

 Things better in Canada:

  1. People are more into fashion and look better on the streets!
  2. Shops close late in the evening
  3. Take care of migrants better (We got unsecured $1000 CAD credit card from RBC on day one!)
  4. Advantages of being close to US
  5. Big cities are more multicultural
  6. (For Iranians) Much more Iranian restaurants, shops and businesses
  7. People in general have higher education levels
  8. Wide highways

Things better in Australia:

  1. Competition at work is less. More relaxed work environment.
  2. Weather
  3. Nature’s beauty
  4. Salaries are slightly higher
  5. New year’s fireworks!
  6. More holidays from employers
  7. Better social rules (driving, etc.)
  8. Public transport system

Bad things in Canada:

  1. Weather
  2. More competition at work and probably longer work hours
  3. You do not see the final price of goods on the label as it depends on tax ! funny !

Bad things in Australia:

  1. Shops close early in the evening
  2. Everything expensive
  3. Less competition in big businesses
  4. Minor hidden racism in some places/people
  5. More poor refugees
  6. Less property construction
  7. Less high rises in big cities
  8. Narrow roads