Skip to content
January 30, 2012

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.


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

	@Id
	PK id;

        //other fields
	
	@Embeddable
	public static class PK implements Serializable{
		public PK (){}
		
		@Column (name="PK_1")
		private Long pk1;
		
		@ManyToOne(fetch=FetchType.EAGER,optional=false)
	    @JoinColumn(name="PK_2")
		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(); 
	    }	

		//getter/setter
	}

	//getter/setter

}

January 17, 2012

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
August 30, 2011

A couple of days with Mac

I have recently bought a 13″/1.8 GHz/i7/256 GB Macbook Air and loving it. I am basically a software developer and linux lover so coming to Mac was a big decision/change. I was basically looking for an OS / machine with these criteria:

  1. Having a proper working version of Skype/Yahoo Messenger/oovoo/…
  2. Linux like
  3. Light machine
  4. Not Windows
  5. Good battery life
  6. Good for development
  7. Having a lot of ports is not a requirement for me. I am very happy with only two USB.
  8. 256 GB hard disk is enough. I have a couple of TBs UBS disks and really do not need to carry all my stuff around with me.
  9. Not having a CD is not an issue. I need to read/write a CD once in a blue moon and that I can manage by sharing a remote CD.

I am really pissed off with recent and ongoing drastic changes in Ubuntu/Unity and Gnome3. They both are really in a state of instability that I hate. Honestly I think at the moment all linux desktops suck. There are always simple things that do not work in linux and you need to switch to Windows for them. I have always liked writings that say good thing about linux (specially Ubuntu) introducing it as the best desktop in the word but let’s be honest, when you can not get a simple scanner or webcam work in a desktop then what is the point ?! I know we can have Skype (which I brought up as examples) in linux but does audio/video always work smoothly? Can you get your webcam connected without hassle or days of command line typing ?! The same sort of arguments go for Yahoo Messenger. Does all the features of Yahoo work on say Pidgin? I brought up these two applications as examples for the sake of argument but this applies to anything from scanners, webcams, printers and many other devices and software.

I was tired of this and wanted a hardware and platform to just work ! Was that a lot to ask?! The only option remaining (except Windows) was Mac and I have always been defensive against it but a bit of research changed my mind. Mac on the other hand can be considered the only POSIX compliant OS that has a working UI. At the moment I use my Mac for home use and some personal development and keep linux just for servers!

Things I like about Macbook Air:

  1. Most of the Windows software have a Mac version and work almost the same way. This is not true for Linux. My DYMO label software writer and Belkin USB network hub as example!
  2. It is very light. Although I do not travel a lot but it is easy to carry around home or take to work and carry on train.
  3. Battery life is great. I charge it during night and the battery works for me the whole day. I work with it 2 hours on the train and a few hours at work.
  4. It is linux like and I do not miss the command line.
  5. UI is great in OSX/Lion. Once you master the keyboard shortcuts, etc your productivity will dramatically increase.
Things I hate about Macbook Air:
  1. You have to get used to Apple way of thinking ! You have to install 3 GB XCode in order to get gcc working on OSX 10.7!
  2. There is no proper package manager in Mac yet as opposed to Ubuntu.
August 26, 2011

reStructuredText Hello World

This is a great tool for creating html pages and presentations and is supported in many languages (I have played with Java and Python tools). This is a Python rst tool:
=====
Title
=====
Subtitle
--------
This is the actual content

- a
- b

1. a
2. b

**what**
   hi
August 26, 2011

Hello WordPress

I am saying goodbye to JRoller (http://jroller.com/rezaghp/) after a couple of years and moving to WordPress. I found WordPress an easier platform to work with. It has more support for code insertion, cleaner editor UI, more modern templates, etc.

JRoller on the other had is really lagging behind technology, at least at the moment. The editor needs huge improvements and does not support many new features, it does not support Ajax, there is no documentation etc.

Anyways!

Follow

Get every new post delivered to your Inbox.