welcome to my world

January 25, 2007

Social Realities

Filed under: Current Affairs — sweetlouie @ 9:06 pm

I watched two war-related films last week of January: Blood Diamond and Innocent Voices.

Brian and I watched Blood Diamond, Tuesday at Greenbelt 3. I thought it was just one of those Hollywood films that were too commercialized to be true and exaggerated beyond imagination but it wasn’t. The film was about the blood diamond setting in Africa. It was referred to as blood diamond because people fight over the control of diamond mines to get money from the market. It was so bloody and brutal. I think I even battered Brian too much because of the graphic scenes. An example would be when one of the rebels cut down the right hand of a captured native so that native won’t be able to vote *shudders* I don’t want to spoil the film for those want to watch, though so I won’t tell the whole story.

While watching the film, my desire to volunteer for the UN became alive again. Ever since high school, I wanted to go to war zones and help people. But then same as with any other "normal" people, I opted to finish a course that would get me a high-paying job (which didn’t happen) and worked for an industry that concerns itself with earning lots of money.

In one of the scenes there, Leonardo DiCaprio said "I am where I’m supposed to be". Am I really where I’m supposed to be?

Then, Thursday, I went out with two close friends, Janice and Grace and watched Innocent Voices (Voces Innocentes). It’s a film about the civil war at El Salvador during the 1980’s. In this movie, boys as young as 12 years old were forced by the military to become soldiers. At an early age, they were exposed to gun shots and bombs every day of their lives. One of their options is to flee the country and go to the US for a chance at a better life. The Grandma there said "Those who leave struggle more. Those who fight stay."

As I look at these harsh realities, I wonder what are we doing to change all these? Do we just let it happen? As it is, a lot of the Filipino people are suffering from war too like in Mindanao and Cordillera. Do we just leave them to face all these?

These are all just questions that enter my mind now and then and yet… here I am still sitting in an air-conditioned room earning my meager salary and being apathetic of these social realities…

January 24, 2007

Hibernate Exercise

Filed under: Information Technology — sweetlouie @ 1:38 am

This post might seem out of place but it is part of my life after all ^_^
 

INTRODUCTION

I
followed the Complete Hibernate 3.0 Tutorial at the roseindia site http://www.roseindia.net/hibernate/index.shtml. You can visit the site at roseindia.net to
get a more detailed explanation of the Hibernate concepts. 

The
tutorial at roseindia.net used Eclipse while the IDE I’m using is NetBeans. Also, this exercise is done on Windows XP.

This
exercise aims to set up the tutorial in NetBeans and impart some of the
difficulties I came across with while setting up Hibernate.

 

REQUIREMENTS 

Download
the following files:

· Hibernate

· MySQL

· MySQL Connector/J

For
this exercise, I used the following versions

· Hibernate 3.2.1

· MySQL 5.0.27

I got my MySQL from XAMPP and running the MySQL service
only. I’m too lazy to set up MySQL from
scratch. For XAMPP, I used the 1.5.5
version.

· Mysql-connector-java-3.1.14

For some strange reason, the mysql-connector-java-5.0.4
doesn’t work with MySQL 5.0.27. I’ve
been around it for days trying to debug the problem but it didn’t work. I searched through Google and I came across
two forums having the same problem as I but there were no solutions posted
there. I’m not sure if the MySQL
community has addressed this issue yet. It seems they haven’t still. While waiting for the fix, I used the older version of the connector
instead, which is the 3.1.14.

In case you’re wondering what error came out when I
used the version 5 of the connector, I posted it below. You might have encountered the same problem.

Exception in thread "main"
org.hibernate.exception.GenericJDBCException: Cannot open connection

at
org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)

at
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)

at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)

at
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)

at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:420)

at
org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:144)

at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:94)

  at
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)

at
org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)

at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2174)

at
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2610)

at
org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:52)

at
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)

at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)

at
org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:139)

at
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)

at
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)

at
org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)

  at FirstExample.main(FirstExample.java:53)

Caused by: java.sql.SQLException: Unknown initial
character set index ‘48′ received from server. Initial client character set can
be forced via the ‘characterEncoding’ property.

at
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:910)

at
com.mysql.jdbc.Connection.configureClientCharacterSet(Connection.java:2345)

at
com.mysql.jdbc.Connection.initializePropsFromServer(Connection.java:3913)

at
com.mysql.jdbc.Connection.createNewIO(Connection.java:2683)

at
com.mysql.jdbc.Connection.<init>(Connection.java:1531)

at
com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:266)

at
java.sql.DriverManager.getConnection(DriverManager.java:525)

  at
java.sql.DriverManager.getConnection(DriverManager.java:140)

at
org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)

at
org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:417)

… 14
more

 

 

SETUP

 

1. Add the JAR files
to your library at NetBeans. At the Projects window, right-click Libraries. Choose Add
JAR/Folder
. Add the following:

For hibernate:

§ hibernate3.jar

§ lib/antlr-2.7.6.jar

§ lib/asm-attrs.jar

§ lib/asm.jar

§ lib/c3p0-0.9.0.jar

§ lib/cglib-2.1.3.jar

§ lib/commons-collections-2.1.1.jar

§ lib/commons-logging-1.0.4.jar

§ lib/concurrent-1.3.2.jar

§ lib/dom4j-1.6.1.jar

§ lib/ehcache-1.2.3.jar

§ lib/log4j-1.2.11.jar

mysql-connector-java-3.1.14-bin.jar

 

2. Run the MySQL
service.

 

3. At the MySQL
server

> CREATE DATABASE hibernatetutorial

> USE hibernatetutorial;

> CREATE TABLE contact (

id INT
NOT NULL,

firstName
VARCHAR(50),

lastName
VARCHAR(50),

email VARCHAR(100),

PRIMARY
KEY(id)

) Type=MyISAM;

 

4. To test the MySQL
connection:

At the Runtime window, expand the Database node. Right-click the Drivers node and select New
Driver
. Click Add on the New JDBC Driver pop-up window and select the mysql-connector-java-3.1.14-bin.jar
then click OK. Right-click MySQL
(Connector/J driver) under the Drivers node then select Connect Using… Replace the
following variables with the appropriate values:

jdbc:mysql://<HOST>:<PORT>/<DB>

e.g. jdbc:mysql://<localhost>:<3306>/<hibernateturial>

 

 

THE
APPLICATION

 

Create
the following XML files.

 

hibernate.cfg.xml

 

<?xml
version=’1.0′ encoding=’UTF-8′?>

<!DOCTYPE
hibernate-configuration PUBLIC

"-//Hibernate/Hibernate
Configuration DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">

<hibernate-configuration>

<session-factory>

<property
name="connection.url">jdbc:mysql://localhost/hibernatetutorial?useOldUTF8Behavior=true</property>

<property
name="connection.username">root</property>

<property
name="connection.driver_class">com.mysql.jdbc.Driver</property>

<property
name="dialect">org.hibernate.dialect.MySQLDialect</property>

<property
name="connection.password"></property>

<property
name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>

<!– thread is the short name for

org.hibernate.context.ThreadLocalSessionContext

and let Hibernate bind the session
automatically to the thread

–>

<property
name="current_session_context_class">thread</property>

<!– this will show us all sql
statements –>

<property
name="hibernate.show_sql">true</property>

<!– mapping files –>

<mapping
resource="contact.hbm.xml" />

 

</session-factory>

</hibernate-configuration>

 

 

contact.hbm.xml

 

<?xml
version="1.0"?>

<!DOCTYPE
hibernate-mapping PUBLIC

"-//Hibernate/Hibernate
Mapping DTD 3.0//EN"

"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

 

<hibernate-mapping>

<class name="Contact"
table="CONTACT">

<id name="id"
type="long" column="ID" >

<generator class="assigned"/>

</id>

 

<property name="firstName">

<column name="FIRSTNAME"
/>

</property>

<property name="lastName">

<column name="LASTNAME"/>

</property>

<property name="email">

<column name="EMAIL"/>

</property>

</class>

</hibernate-mapping>

 

 

Create
the following java files.

 

Contact.java

 

/**

* @author Deepak Kumar

*

* Java Class to map to the datbase Contact
Table

*/

public
class Contact {

private String firstName;

private String lastName;

private String email;

private long id;

 

/**

* @return Email

*/

public String getEmail() {

return email;

}

 

/**

* @return First Name

*/

public String getFirstName() {

return firstName;

}

 

/**

* @return Last name

*/

public String getLastName() {

  return lastName;

}

 

/**

* @param string Sets the Email

*/

public void setEmail(String string) {

email = string;

}

 

/**

* @param string Sets the First Name

*/

public void setFirstName(String string) {

firstName = string;

}

 

/**

* @param string sets the Last Name

*/

public void setLastName(String string) {

lastName = string;

}

 

/**

* @return ID Returns ID

*/

public long getId() {

return id;

}

 

/**

* @param l Sets the ID

*/

public void setId(long l) {

id = l;

}

 

}

 

 

FirstExample.java

 

import
org.hibernate.Session;

import
org.hibernate.SessionFactory;

import
org.hibernate.cfg.Configuration;

 

 

/**

* @author Deepak Kumar

*

* http://www.roseindia.net

* Hibernate example to inset data into Contact
table

*/

public
class FirstExample {

public static void main(String[] args) {

Session session = null;

 

try{

// This step will read hibernate.cfg.xml
and prepare hibernate for use

SessionFactory sessionFactory = new
Configuration().configure().buildSessionFactory();

session =sessionFactory.openSession();

if(session.isConnected()) {

System.out.println("connected");

} else {

System.out.println("not
connected");

}

//Create new instance of Contact and
set values in it by reading them from form object

System.out.println("Inserting
Record");

Contact contact = new Contact();

contact.setId(3);

contact.setFirstName("Deepak");

  contact.setLastName("Kumar");

contact.setEmail("deepak_38@yahoo.com");

session.save(contact);

System.out.println("Done");

}catch(Exception e){

System.out.println(e.getMessage());

}finally{

// Actual contact insertion will happen
at this step

session.flush();

session.close();

}

}

}

 

 

Sample Output

init:

deps-jar:

compile-single:

run-single:

log4j:WARN
No appenders could be found for logger (org.hibernate.cfg.Environment).

log4j:WARN
Please initialize the log4j system properly.

connected

Inserting
Record

Done

Hibernate:
insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)

BUILD
SUCCESSFUL (total time: 1 second)

 

RECOMMENDATIONS

 

This
exercise is just an initial step to learning Hibernate. It can be further extended to include more
tables and SQL operations. A lot of
Hibernate tutorials are available on the net for additional references.

January 19, 2007

Nostalgic

Filed under: Sociology and Society — sweetlouie @ 9:36 pm

As I entered the PCHRD office on a Saturday, nostalgia hit me really hard. I missed the office, its familiar surroundings, the people whom I’ve come to know the past 6 years, my cluttered desk, even my pc… everything.

You see, PCHRD is where I grew up. This is where I learned to deal with different kinds of people. I’ve encountered bossy, noisy, authoritative, annoying, quiet and sly people. But this is also where I found my second family. This is where the PCHRD Jologs started. It started with a few young RICUP staff then: Eyna, Misyel, Mayet, Lorena, Anya, Alex, Fred and me. Then later on, every new young employee became part of our family. And every year it just keeps on growing and growing.

But then things do change. As the saying goes, change is the only permanent thing in this world. We go our separate ways. We find greener pasture. We seek happiness elsewhere. We get better opportunities.

In this one-room office, I have shared so many memories with friends and loved-ones. Laughter at cubicles and each corner. Tears at the server room, also known as the confession room. And as I enter through the front door, all the memories came rushing back despite the silence, the stillness.

Many more will come and go and I will move on to other places but PCHRD will always remain special in my heart. And I know it does, too, with other Jologs out there.

HAPPY 25TH ANNIVERSARY, PCHRD! ^_^

January 15, 2007

Pampalipas Oras

Filed under: Random Thoughts — sweetlouie @ 10:07 pm

I’m currently at my desk doing nothing. I’m new to my job, been here just two days past. I haven’t been assigned anything yet. I’ve been waiting for my boss to assign me to a group.

So, anyway, while doing nothing, I’m here writing my first blog at Friendster. I used to have a blog but unfortunately it hasn’t been updated for quite some time now. And I guess the entries there didn’t really fit my current status right now *grins*.

This is my second job. Is this really how it works when you’re new to a company? Or maybe because the company I’m currently in is still new so they are still groping their way around their operations?

What do you usually do when you’re new to a company? The first day is the most boring and exciting day, I guess. When you come in to the office you feel so excited and giddy with anxiety. As soon as you get there, they let you read the company profile, sign up some forms that the HR needs, meet people in the office then sit at your desk and wait for your boss to tell you what to do. (I realized this must apply only to rank and file staff. I haven’t had a managerial position yet so I don’t know how they go about their first day at work.)

Now, I’m writing a blog. I didn’t have anything else to do. I’ve been reading some tutorial stuff that I think is related to my work but I’m not really sure if I can use it. I’ve been chatting with my new officemates, too. But after some time you can’t find anything to talk after all. Then again, I just met them so I haven’t really discovered any common ground with them yet.

So this is how my first few days at my new company has gone. I do hope I’ll have an assignment by tomorrow. Darn, I don’t like doing nothing at all.

WPMU Theme pack by WPMU-DEV.