Semakin tinggi jabatan, semakin tinggi prestise dan kebanggaan tapi semakin tinggi pula tanggung jawab yang diemban.

Apakah kita harus siap dahulu baru kita bisa memegang jabatan yang lebih tinggi, atau kita memegang jabatan yang lebih tinggi dulu dan saat kita memegang jabatan, kita membuat diri kita jadi siap?

Misalkan saya pilih siap dahulu,mungkin kita akan siap suatu saat kelak, tapi pastinya lebih lama, karena tidak ada dorongan dan tekanan kuat, kalaupun ada cuman diawal-awal.

Misalkan saya pilih jabatan dahulu, mungkin kita akan merasa tertekan, ringkik dan merasa serba salah, tapi karena ada dorongan dan tekanan kuat, niscaya sejalan dengan waktu, jabatan itu akan membuat diri kita siap.

Namun tetap berpegang pada yang kuasa, karena hanya Dia-lah yang bisa menolong kita disaat-saat penuh tekanan tersebut.

Ketika seseorang mengejar 2 kelinci, dia tidak akan mendapatkan satu kelinci pun.

Tapi bila kita mengejar satu kelinci , kemudian mengejar kelinci lain setelah mendapatkan kelinci pertama, niscaya kita akan dapat kedua-duanya. kecuali pas lagi apes.

Begitu pula dengan tujuan, mengejar tujuan secara bersama-sama tidak akan membawa kita ketujuan itu. Lebih baik kita fokus pada satu tujuan, kemudian beralih ke tujuan lain setelah tujuan pertama tercapai. bila kita beruntung, kedua tujuan tersebut bisa kita raih.

Nah sekarang waktunya untuk mengejar tujuan.

Understanding Hibernate

Suppose we have simple message board that contain three classes

messageboarddb1

If we using JDBC, we have to maintain the relationship between Topic and Post manually,  but if we use Hibernate, hibernate will do it for us.

The Steps To Using Hibernate

  1. Create object model (POJO) for the class
  2. Configure the mapping file, this is connector between your database schema with your POJO
  3. Build database schema
  4. Configure hibernate

Step 1.

We create POJO for the class (Topic class, Post class and User class)

package discussion

import java.util.*;

public class User{
    private String id =null;
    private String password = null;
    /**
    * we need constructor without parameter
    * because hibernate needed
    */
    public User(){}
    public User(String id, String password){
        this.id=id;
        this.password=password;
    }

    public String getId(){
        return id;
    }
    public void setId(String id){
        this.id=id;
    }
    public String getPassword(){
        return password;
    }
    public void setPassword(String password){
        this.password=password;
    }
}

/**
* Topic class
*/

public class Topic{
    private String id=null;
    private Date timestamp=new Date();
    private Date modified = new Date();
    private List posts = new ArrayList();
    public Topic(){}
    public String getId(){ return id; }
    public void setId(String id){ this.id =id; }
    public Date getTimestamp(){ return timestamp; }
    public void setTimestamp(Date timestamp){this.timestamp=timestamp;}
    public Date getModified(){ return modified;}
    public void setModified(Date modified){this.modified=modified;}
    public List getPosts(){retun posts;}
    public void setPosts(List p){this.posts=p;}
}

/**
* Class Topic
*/
public class Post{
    private Long id;
    private String subjct;
    private String text;
    private User user;
    public Post(){}

    public String getId(){ return id; }
    public void setId(String id){ this.id =id; }
    public Date getTimestamp(){ return timestamp; }
    public void setTimestamp(Date timestamp){this.timestamp=timestamp;}
    public Date getModified(){ return modified;}
    public void setModified(Date modified){this.modified=modified;}
    public List getPosts(){retun posts;}
    public void setPosts(List p){this.posts=p;}
}

After finished, then create mapping. The mapping will be describe in chapter 2

In this part, we will describe the mapping from object model and database schema.

We have three class, so we have to create three mapping file. in this example i created mapping file for User class to gain basic understanding about mapping.

<hibernate-mapping>
   <class name="discussion.User" table="users">
      <id name="ID"
          column="id"
          type="string">
          <generator class="assigned"></generator>
      </id>
      <property name="password"
          column="password"
          type="string" />
   </class>
</hibernate-mapping>
  • <class name="discussion.User" table="users">
    Class name is fully name of class, it mean the name of class with the package (in my example before i created POJO class named User in package discussion, so the fully name of my class will be discussion.User)
  • The table is the table name in database.
  • Id tag is identifier tag, identifier is like a primary key in database.
  • Property is field name other than primary key.
  • <property name=”password” column=”password” type=”string” />
    Id tag and property tag have name,column and type. the name describe the name in POJO, the column describe the name in database. in example, in table User we have a field named Password, in POJO we have a property named password. to connect each other we have to fill name with password and column with Password.
  • <generator class=”assigned”></generator>
  • this tell hibernate that the creation of Id is handle by application, in example my database is set to auto increment, so  the database handle the creation of this field.

Type

All the element have a type in hibernate, the mapping type is listed below :

The List of Type (Standard)

Mapping Java SQL
Integer int or java.lang.Integer INTEGER
long long or java.lang.Long BIGINT
short short or java.lang.Short SMALLINT
float float or java.lang.Float FLOAT
double double or java.lang.Double DOUBLE
big_decimal java.math.BigDecimal NUMERIC
currency java.util.Currency VARCHAR
character java.lang.String CHAR(1)
string java.lang.String VARCHAR
byte java.lang.Byte TINYINT
boolean java.lang.Boolean BIT
yes_no java.lang.Boolean CHAR(1)
true_false java.lang.Boolean CHAR(1)

List of Type (Date)

Mapping Java SQL
date java.util.Date or java.sql.Date DATE
time java.util.Time or java.sql.Time TIME
timestamp java.util.Timestamp or java.sql.Timestamp TIMESTAMP
calendar java.util.Calendar TIMESTAMP
calendar_date java.util.Calendar DATE

List Of Types (Binnary and Large object types)

Mapping Java SQL
text java.lang.String CLOB
binary byte[] VARBINARY or BLOB
seriallizable any java class that implement java.io.Seriallizable VARBINARY or BLOB
clob java.sql.Clob CLOB
blob java.lang.Blob BLOB

Notes : BLOB = Binary Large Object

CLOB = Character Large Object

Generator

Generator are special tagi inside id tag, it describe how hibernate generate primary key.

Generator Name Description
identity It supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.
increment It generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. It should not the used in the clustered environment
assigned lets the application to assign an identifier to the object before save() is called. This is the default strategy if no element is specified.
native It picks identity, sequence or hilo depending upon the capabilities of the underlying database.

Quick Trick :
in case we created autoincrement id in database, so used native generator.
in case we created id manually (by application), so used assigned generator.
in case we not created autoincrement id or we wont created id manually, we can use increment(in not clustered environment)


Hibernate

Hibernate is one of ORM (Object Relation Mapping) that gain popularity in java community.

As an ORM, hibernate  simply persistent java object into  relational database, making programmer working with classes and object instead of queries and result set.

The Benefit :

  1. Hibernate  make programmer write less code to achieve the same result, i.e. all the CRUD (Create, Read,Update and Delete) are handled by simple API so we don’t need to create messy ODBC or JDBC data access.
  2. Hibernate enriched with HQL (Hibernate Query Language), the optimized SQL query to perform query more better and efficient
  3. Hibernate currently support all the popular RDBMS ( more than 20 RDBMS).
  4. Hibernate simply portability, because to switch from one RDBMS to another is simply be changing configuration file.
  5. Hibernate is lightweight ORM solution, so the performance penalty of using ORM would be minimizes
  6. Hibernate group is currently very active and produce a number of enhancement to push hibernate into perfect ORM solution

New is software enginering? or want to prepare your carier in software enginering?

I hope this advice will help you.

First Advice is Master Your Tool

“Learn to  use your tools And I don`t mean just enough to get by. I mean really learn how to use your tools”

Like :
- Know all menu available and functionality
- Remembering shortcut for the most used function
- Using debugger, profiler and version control integration

Just my share, when i first get job in Java (before that i using VS2005), i get job to fix bug in clinic system, my supervisor alocate 4 hours to fix the bug, just  a minuete.. i`m new in Java, the program it self is new for me, then in reality, i spend 4 hours just to get the source from repository to my eclipse IDE, then i took 4 hour again to understand the flow of the code and  8 hour to fix the problem.. what an inefisient of time. Another bug, also took longer than i expected, i have to take another hours outside office hour to tackle it.

Then  after a couple of days i got another bug-fixing job again, in this case, my supervisor trust me to estimate the time.  He said, you have to know why the bug is appear after that you can estimate the time require to fix that bug.

After 2 hour of clicking the IDE, trying to find the bug, my supervisor and project manager came to me, then they ask me, how about the estimate time?…  Then my supervisor look the editor screen  and click-and cliking, then after 10 minuete he said, 6 hour would be fine..
What i learn here is, Eclipse (Tool) have very great tool for debuging, and i dont know how to use it (like watch, inspect,jump,jump into dll), that why i took more than 2 hour to look after the bug. So really get know your tool, it save you alot of time. Trust me.

Second Advice is Learn the platform APIs

(Dont Reinvent The Wheel)

” Make sure you have a good grasp of all the available functionality in the platform before you write your own code”

For example, you want to reverse something, but there`s no reverse() method in java.util.List . But not so fast –don`t write it yourself. There`s a collections class that contains a lot of utility methods that operate on collections, like List, and it provide a reverse() method.

Just my own share, when i have to enhance clinic system, i have to change the old format to new format of patient Id. The new format contain six digit fixed number (i.e. 000001).  I searching in String class, and cannot find the function i need, the i create the function, well, it quite simple, but after my partner review it he say that you dont have to reinvented the wheel, because the function you create already in  Java utilities(left()) If i know it before, it would save me for couple of hour.

The first and second advice is from Tor Norbye, he is a principal engineer at Sun Microsystem, where he has worked on development tool since 1996, most recently on Ruby and JavaScript editor in the NetBeans IDE, he has a master’s degree in computer science from stanford university.

Third Advice is Master The Programing Concept

“Don`t overwhelmed by the language or the platform”

if you breaking down, the basic of the language are based on object-oriented programming, threading, concurrency and event-driven programing. it`s necessary to become a master of these concepts since the rest of your careee will depend on this foundation


The third Advice is from Raghavan Srinivas he is  Sun Technology Evangelist


Fourth advice is decide your general and special skill

Chunk-munn Lee said that you have to choose what are of your immediate need (special skill), and Scott guu said that you have to know what technology for what problem(general skill).
Both of them said that it`s hard to get deeper knowledge and skill in all the technology in software engginering, but its important to know what technology used in what situation.

Fourth  advice is from Chunk-Munn Lee An Java Evangelist and Scott Gu`e an Techinical Leader from Microsoft

Last Advice is CANI (Continues and Never Ending Improvement) Skill

This advice come my favorite motivator, anthony robbins, i think this advice is applicable for all human life including software enginering to :)