Actually i am using CMP (calling from stateless session bean) in our project.
In interview :),
1)they are asking, why you are using CMP?
I told container is responsible for writing JDBC access code and Synchronization. Apart from this, they are expecting something. Could you please explain? any merits.
Other quesion is,
2)why people are not using entity bean?
Please explain. Do not ignore it. :)
The advantage of Using CMP is
1.Our Container is responsible for implementing all persistence logic.
2.We can use all the services provided by the container like security,Transcations..etc.
3.We need not to bother if database need to be changed at any point of time,Cause our container will take care while deployment after we configure the datasource.
People are not using entity beans now a days cause the new data persistent tools are there which are easy to use and maintain like Hibernete.We can use Java dataobjects instead of entity beans.
Thank you very much. Any advantages regarding Performance? if anything, please reply.
Although CMP 2.0 is far better that the previous versions but still it's not that good for large projects. If you are talking about small projects where the data is very limited then CMP is ok but for large projects where you want more control on the SQLs generated and where you are concerned about the response time of SQl execution you will most probably like to code JDBC.
The CMP makes sense in a way that you don't have to code the persistence logic but the places where you have many relationships it become very difficult to manage all those XMl files etc.
Further performance is again a issue. One database row will be represented by one java object. And these objects will stay on the heap and will consume memory. All the good application servers provide a way to configure that how the objects should be made (I mean to create a pool while server startup to represent all the data in the database or have limited number of object, the first approach will be very efficient but then again its a memory issue).
In the end I believe that CMP still needs a couple of years to emerge as a good technology.
I Faced one Interview they asked me, CAN WE USE INSTANCE VERIABLE SIN STATELESS SESSION BEANS? IF YES, WHY AND HOW? IF NO, WHY AND HOW?
PLEASE REPLY IT.
Should I just show up at your office and do your work for you?
I think it depends on our code. If we are using container specific code then no need to create instance varibles. If our code is our own specific, then we can create instance varible.
But in general, in any books it is clear that no need to create any instances in stateless beans.
I need get lot on this. Please reply this.
These are some of the primary advantages of CMP, which I can think of..!
1)Speed of development.!
2)Only declarative dependency to the underlying database..!
3)No code changes when switching from one db vendor to another, only deplyoment descriptors needs attention.
4)Data manipulation easy through create(), findbyXXX(), remove() methods..!
5)Container specific transactional integrity..!
1) Findermethods() can crash the system,, imagine calling findall() on a CMP bean with 100K+ records;)
2) Resource intensive and less efficient when implementing relations;) findbymethods less eficient, you may want to go JDBC/BMP route for effectieve reporting etc..!
3;) there are another 101 more..!