• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

What is this POJO

 
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In a project I was using DAO and EJB (session), while it was called that the project was using POJO.
But I could not really see something different than using DAO pattern.

Would you be able to ellaberate why this POJO word is there.
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
POJO : Plain Old Java Objects
but depending on the context, one may have referred EJBs also as POJOs
 
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Yilmaz Mete:
POJO : Plain Old Java Objects
but depending on the context, one may have referred EJBs also as POJOs



If you did, you would be making a mistake. EJBs need the container to run, POJOs don't, so EJBs are not Plain java objects.
 
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the EJB 3.0 version all bean classes will be POJO.
 
Paul Sturrock
Bartender
Posts: 10336
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...unless of course you are talking about Session EJBs. Or Message Driven EJBs.
[ January 24, 2006: Message edited by: Paul Sturrock ]
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I'm not querying about EJB.

My question is why there is a concept like POJO? Anyway from the very begging of Java we were using Java objects but now those Java objects are given the name as POJO. But it's just the same Java objects.

So are we using a new word without saying just Java Objects?
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kamal,
Googling gave me this
POJO

Looks like �What's is there in a name� has became deprecated.
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mmm.. Great Manoj, it has something like this.

"We wondered why people were so against using regular objects in their systems and concluded that it was because simple objects lacked a fancy name. So we gave them one, and it's caught on very nicely."



If that's just talking about Java Objects do we have to think anything more? It's just like learning J2SE. Is that correct?
 
Ranch Hand
Posts: 150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kamal Mettananda:
If that's just talking about Java Objects do we have to think anything more? It's just like learning J2SE. Is that correct?



Hi Kamal,

In the beginning there were only ordinary Java objects. Then along came EJBs and the like, which are more complicated Java objects. Everybody seemed to jump on the EJB bandwagon, and all objects created for an enterprise system were being created as EJBs. In order to differentiate between the ordinary objects and EJBs, the term POJO was created to refer to "ordinary" Java objects, i.e. non-EJB objects.

You are right that POJOs are written in J2SE, and do not include J2EE concepts like servlets, EJBs, etc., nor does a POJO include graphic concepts like AWT, Swing which are included in J2SE. A POJO is an object which simply contains data and methods, and nothing fancier.

Regards,

Fintan
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Fintan,

So there are two types, POJO and EJB.

A POJO is an object which simply contains data and methods, and nothing fancier.



Ok good. But there's still a word for those saying Java Beans which is used to express about the objects that contain data and getters and setters.

So the main difference between a Java Bean and a POJO is that it has some business methods other than the getters and setters.

That is Java Bean is a subset of POJO..

Hope this is correct.
 
Manoj Kumkumath
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


A POJO is an object which simply contains data and methods, and nothing fancier.



I think what Fintan mean is that POJO doesn't use any fancy stuff like container for getting thing done. I think we can not say that we use/don't use POJO at class level. It should be taked in a higher lever like how our application is persisting the data to db. Is it using plain java classes or Is it using fancy stuff like an CM persistence.
 
Ranch Hand
Posts: 249
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To put it in laymen's terms, POJO is just using basic Java - not getting fancy. Am I right?
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I never heard POJO, I would like to find out more about it.
 
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

See the post I made in https://coderanch.com/t/216003/ORM/java/Chris-Richardson-do-you-call that discusses the definition of a POJO.

The big idea behind POJOs is separation of concerns. So rather than write code that implements business logic and infrastructure concerns such as transactions, security etc, you separate it out.

Your POJOs implement the business logic. They are written using simple Java without implement infrastructure framework-specific interfaces or calling framework-specific APIs.

You then use non-invasive frameworks such as Spring, Hibernate and EJB3 to provide persistence, transactions et etc.

The benefit of this approach is that you can develop and test your business logic without worrying (so much) about application server, the database and the infrastructure frameworks. As a result, development is simpler and faster. You can focus on one thing at a time. You don't have to be an infrastructure framework expert to work on the code. Moreover, you can also switch/upgrade frameworks without having to rewrite your code.

POJOs and JavaBeans are two orthogonal concepts. A JavaBean doesn't have to a POJO and a POJO does not have to follow the JavaBean naming conventions. In fact, well-designed objects should not expose their fields via getters and setters unless it really is required. But that's a whole other thread.

Chris
[ January 24, 2006: Message edited by: Chris Richardson ]
 
Pradeep bhatt
Ranch Hand
Posts: 8946
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

You then use non-invasive frameworks such as Spring, Hibernate and EJB3 to provide persistence, transactions et etc.



Doesn't using annotations invasive ?
 
Chris Richardson
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pradip

Yes. Annotations are invasive. See my message about this topic in this thread: http://www.javaranch.com

Chris
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

According to ur explanation it is clear that java objects are called POJO when they use the basic J2SE level rather than using Framework specific classes or jars. And they basically target on the business logic.

So is it correct to say that POJO is used in the DAO Pattern where the objects are independent of the DBMS?

But one thing is not that clear for me.


Originally posted by Chris Richardson:
POJOs and JavaBeans are two orthogonal concepts.



I feel that both are a bit similar compared to EJB as non of those use any framework specific parts, except that Java Beans are used to store data while POJO are used to store data & business logic.
[ January 25, 2006: Message edited by: Kamal Mettananda ]
 
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
POJO=PO?
PO is Persistence Object
 
Chris Richardson
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Billy Tsai:
POJO=PO?
PO is Persistence Object



Some POJOs (Plain Object Java Objects) are persistent where as others are not. e.g. an entity such as Account could be persistent where as a service such as MoneyTransferService is not.

Chris
 
Chris Richardson
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Kamal Mettananda:
Hi Chris,

According to ur explanation it is clear that java objects are called POJO when they use the basic J2SE level rather than using Framework specific classes or jars. And they basically target on the business logic.



My book POJOs in Action is about the backend (business and database access tiers) but the idea of POJO also applies to the presentation tiers. e.g. POJOs are not coupled to the Servlet API where as non-POJOs are. Compare, for example, WebWork actions with Struts Actions.

Originally posted by Kamal Mettananda:
So is it correct to say that POJO is used in the DAO Pattern where the objects are independent of the DBMS?



DTOs are typically POJOs but they are not particularly interesting objects since they contain only data, no behavior.

Originally posted by Kamal Mettananda:
But one thing is not that clear for me.

I feel that both are a bit similar compared to EJB as non of those use any framework specific parts, except that Java Beans are used to store data while POJO are used to store data & business logic.



JavaBeans that are used as DTOs are typically POJOs as I mentioned above. However, strictly speaking:
* JavaBeans - a naming convention
* DTO - the role of an object
* POJO - a class that does not implement special interfaces

Chris
[ January 25, 2006: Message edited by: Chris Richardson ]
 
Billy Tsai
Ranch Hand
Posts: 1327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Assuming I have POJO for persistence purpose and one POJO inherits an class ( extends) and that POJO has one to many relationship with another POJO do u think the POJO on the many side should automatically extends the same class too?
 
Chris Richardson
author
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Only if makes sense in your object model.

Chris
 
Kamal Mettananda
Ranch Hand
Posts: 51
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

This is quite interesting.


Originally posted by Chris:
* POJO - a class that does not implement special interfaces



So I understand that Plain in POJO really means it's plain.
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"Plain old"

I think the chriteria to explain the stuation is they are the simplest objects to store and delegate the records that is related...

"Plain" and "old" like we begin to write java classes at first.Plain and old when we were beginner.I think those words have chosen because sun and everybody else are developing other complex things to persist datas.

Before EJB 3.0 there was too much arguments to persist the datas..
I think "plain old" is an answer such as "no need to complexity.No needed to implement too much complex interfaces and classes.)
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
POJO's are called Plain Old Java Objects. They are very similar to the regular java objects we use.Its just a name to differentiate it from EJB's
 
reply
    Bookmark Topic Watch Topic
  • New Topic