Tom Kowalski

Ranch Hand
+ Follow
since Feb 17, 2009
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Tom Kowalski

Hello. I would like to notice, that although this forum let the user to change his 'name', it is not working 100% correct. All 'old' posts are being changed, so the name of their author is changed, but the part 'This message was edited 2 times. Last update was at <<date>> by XXX YYYY', where 'XXX YYYY' points to the 'old' name of the user. You should definittly change it!.
12 years ago
I don't want to be rough, but you have just 'read' what I have put in code. Nothing more, nothing less.
I have discovered today really strange (for me) thing in Java. On one hand it makes sense, but on the other, I just want to scream 'What the heal?'. I put it here, because it might be useful for people who are learning for SCJP.

I strongly recommend you reading FAQ before creating this kind of topics. And you could use also 'search' button, you will find about 1000 topics with this question. The SCBCD exam covers EJB 3.0, Head First is about EJB 2.1 - this is a big difference.
If I were you I would try to reduce the area in which there is cause of this error. Have you tried to comment (//) the code inside the method of the bean? Try to do this, is the error still thrown.

It would be easier if you would write the code of your bean and the the code of your client

Probably this is simple question, but I just can't find the answer. What should be in the place of XXXX in this query? I have been trying java.lang.String.class and java.lang.Long.class but it doesn't work...
Yeah, they are in this same application. Strange. Sorry, I won't be able to help you.

Anyway, I agree with you, beans attributes (name, mappedName etc.) are quite stupid :P. It's really hard to find anywhere good information about how to use them properly (from A to Z). Here is a webpage which can be quite useful while you are learning about it:
Are you sure that the session beans and the servlet are parts of the same application? (In other words, have you made EE Application, where you have got: ejb part (session beans), and war part (servlet)?

P.S Injecting session beans is one of the most stressful things at the beginning of EJB learning. Really.

Sandeep Vaid wrote:Here the overridden method SiameseCat.postPersistAnimal() is called and Animal.postPersistAnimal() is not at all called.

The overriden method is Animal.postPersistAnimal() not the SiameseCat.postPersistAnimal()

Animal.postPersistAnimal() -> overridden method
SiameseCat.postPersistAnimal() -> overriding method
Are you sure that you deployed the SessionBeans? And secondly, there is a serious error in you code

You wrote

you should inject the interface

JNDI sees the business interface, not the class itself. Depending on whether you will use methods from the local or remote interface, you should inject the correct interface - then the right session bean will be injected
You can't use Dependency Injection (@) in the methods. So this won't work. Servlet's local variables are thread safe, so if you want to use session bean, you should use lookup method from the InitialContext.

It all depends of the type of the bean, if you have got stateful bean you shouldn't use DI, but if the beans are stateless you can use it and don't worry about thread safe.

And now your second question. Again it depends of the bean type. If the bean is stateless there will be just a few (probably, but it ofcourse depends on the configuration) beans in the pool, and all the 'users' will use them - these few beans . When they will be created (@PostConstruct) - the data connections will be open, and thanks to this, everybody will use it. Stateless beans are not created very othen. It would be very bad if you would open connection in the business method - then, every request would open the connection - this would be inefficient.
// EDIT: I have found the answer ( the topic can be deleted. sorry.

Bean interface:

Bean class

This is bean, which I deploy with an EE Application. I want to get access to this bean in the servlet, when I am doing this by @EJB injection everything is working. But I can't get the bean through the lookup method

It throws exceptions all the time (javax.naming.NameNotFoundException). Could somebody tell me how to fix it? thanks...

(NetBeans + GlassFish)

Servlets are not thread safe. If you want to make it Servlet as Thread safe, you can implement SingleThreadInterface which is a blank Interface there is no methods (this is not recomend method, because it could slow the performance of your page) or you can synchronize methods by using synchronized keyword. Anyway, this is quite basic question, try to use google in this case, you will find a lot of pages with a full story about this .
14 years ago