What is difference between JPA and Hibernate as they both cater for DB persistence work in Java? Well again this is the "fight" between official and de facto standard. Long before those so-called industry experts wake up to note down a standard addressing a well-known enterprise application development issue, several groups of smart doers already raised up to invent their own "proprietary" solution to the problem. The issue is known as ORM while the groups of smart doers included Hiberate creators, Oracle's TopLink as well as the team of bringing live iBatis. The standard is JPA.
The primary reason to embrace JPA is driven by the thirst of having a standard in Object-Relational mapping - paint the door once, changing the lock often doesn't hurt (one interface with many implementation alternatives. Ideally one can be replaced by another if one doesn't suit the course anymore). However, the reality that Hiberate 3 implements JPA enables early Hibernate adopters to stay on their course while having a standard architecture in front of their governance board. In case of Red Hat deciding to discontinue open sourcing Hibernate, JPA users can switch to another implementation like OpenJPA.
On practical side of story, I would rather recommend to use Hibernate for a JPA implementation. For things that JPA can't resolve easily, use Hibernate "proprietary" features (e.g. hibernate-specific annotations). One's chance to replace a backend implementation is as uncommon as a major Open Source project getting killed. Here I said major. If you really sense the uncertainty of Hibernate and thus want to fully stick to JPA, still use Hibernate, just keep no hibernate-specific stuff.
The blog is solely a platform for self-expression on topics out of personal interests, view of current affairs, especially those related to China, economy and social phenomenon. As far as it is called an opinion, it is biased and hardly judged as objective. My blog posts in this site and any other site have no relation to my current or previous employers, nor does it have anything to do with business those companies operate in.
Friday, November 27, 2009
Composition vs. Aggregation
They both are within the context of OO design and both refer to a form of object ownership - one object contains one or many other objects.
The difference lays in the strictness of the ownership. For composition, it implies an ownership of lifetime. From implementation aspect, the compositor manages the lifetime of its containing objects. If the parent gets GCed, its composed objects are all gone away with it. Composition is thus of owning by value (does pass-by-value sound familiar?)
On the other hand, aggregation is a weaker form of ownership. In other words, if aggregator is dead (GCed), its aggregated objects will still happily live in the heap (memory heap). Under this context, aggregation is of owning by reference (Pass-by-reference as oppose to pass-by-value).
A code snippet for composition would look like this
class Compositor
{
Object obj1;
Object obj2;
public Compositor ()
{
this.obj1 = new Object();
this.obj2 = new Object();
}
}
Here is an example of aggregator
class Aggregator
{
Object obj1;
Object obj2;
public Aggregator (Object obj1, Object obj2)
{
this.obj1 = obj1;
this.obj2 = obj2;
}
The difference lays in the strictness of the ownership. For composition, it implies an ownership of lifetime. From implementation aspect, the compositor manages the lifetime of its containing objects. If the parent gets GCed, its composed objects are all gone away with it. Composition is thus of owning by value (does pass-by-value sound familiar?)
On the other hand, aggregation is a weaker form of ownership. In other words, if aggregator is dead (GCed), its aggregated objects will still happily live in the heap (memory heap). Under this context, aggregation is of owning by reference (Pass-by-reference as oppose to pass-by-value).
A code snippet for composition would look like this
class Compositor
{
Object obj1;
Object obj2;
public Compositor ()
{
this.obj1 = new Object();
this.obj2 = new Object();
}
}
Here is an example of aggregator
class Aggregator
{
Object obj1;
Object obj2;
public Aggregator (Object obj1, Object obj2)
{
this.obj1 = obj1;
this.obj2 = obj2;
}
Wednesday, November 18, 2009
How to set up JAVA_HOME on Mac
locate your .profile file and
put in export JAVA_HOME='/usr/libexec/java_home'
This will automatically pick up whichever java home variable set via Java Preference on Mac.
put in export JAVA_HOME='/usr/libexec/java_home'
This will automatically pick up whichever java home variable set via Java Preference on Mac.
Tuesday, November 17, 2009
Thanks for my friend Rob sharing on this
Watch your thoughts; they become words.
Watch your words; they become actions.
Watch your actions; they become habits.
Watch your habits they become character.
Watch your character; it becomes your destiny.
In other words, success can be made if not born with.
Watch your thoughts; they become words.
Watch your words; they become actions.
Watch your actions; they become habits.
Watch your habits they become character.
Watch your character; it becomes your destiny.
In other words, success can be made if not born with.
Subscribe to:
Posts (Atom)