Win a copy of OCP Oracle Certified Professional Java SE 11 Developer Practice Tests this week in the OCP forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Ron McLeod
  • Tim Cooke
Sheriffs:
  • Devaka Cooray
  • paul wheaton
  • Mark Herschberg
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Frits Walraven
  • Jj Roberts
Bartenders:
  • Carey Brown
  • salvin francis
  • Piet Souris

Bean Lookup Using Custom Constructor

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi. I have a stateful bean deployed on a JBoss server, and I look it up using the following code:



The problem is this instantiates the bean using its default constructor. What do I do if want to pass parameters to it when I create it?

Thanks,
Jeff
 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jeff Storey,

I am not very sure whether you can call oveloaded(parameterized) constructor when you are calling a bean through JNDI look up. But i would suggest a workaround to your problem. Lets create a syncronized copy of object(with the properties which you need to pass in parmetrized constructor) and then do pass instance of that object as parameter in your businnes method.

In you business method you can deserialized that instance and get the copy of the properties which you are in need of.
I hope this would help you up......

Cheers !!!
Sumit Malik
 
Sheriff
Posts: 10445
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a Stateful Session Bean you can have a create method which accepts parameters, in the remote/local home interface. Then when you create the bean using the home interface, you can pass the parameters through the create method.

Something like:

 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for that answer. I don't actually use a create method though, since I am using EJB3, I didn't think I had to...
 
Sumit Malik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey Jeff when you are playing with EJB 3.0 then you dont have flexibility of home interface and you are dealing directly with remote/local interface(where actually you have defined you business method).

You can get desired result as Jaikiran Pai has pointed out with overloaded create method in ejb2.x series(because ejb3.0 has backward compatibility) or you can try out with passing parameters in business method(if you are initializing any member variables of ejb through constructor) in reote/local interface.

Cheers !!!
Sumit Malik
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumit,

I understand the first suggestion you made about using the create method. I'm a little unclear about the second statement: "try out with passing parameters in business method(if you are initializing any member variables of ejb through constructor) in remote/local interface."

Does that mean to use another method to initialize the parameters (instead of the constructor) or is there a way to actually pass the parameters to the constructor when I am initializing the ejb?

Thanks,
Jeff
 
Sumit Malik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jeff Storey,

Well, I hope you must be initializing some members variables of ejb through constructor(with parameters) and then you must be manipulating your business logic as per the state of member variables.

I am suggesting just call default constructor(through remote interface) and then call business method from this instance. When you are calling business method(modify the signature of that method by adding the parameters which you are initializing through constructor) then just through the values of those parameters you can define(or manipulate) your business logic.

I hope now you must have got the idea


Cheers !!!
Sumit Malik
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sumit,
But Jeff wants those values to be passed dynamically while lookup, from the calling program. I am not clear about, How he will be able to do it with your suggetion?

Regards,
Dharmendra.
 
Sumit Malik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dharmendra,

Well, If Jeff is using EJB3.x series then you know we dont have the concept of home interface where we define our create(default or overloaded) methods. If Jeff needs to pass those parameters dynamically then He needs to pass those values(which he is initializing through constructor) in their defined method of business interface(local/remote).

I think this is the solution what he is looking for. Can you suggest some workaround ???

Cheers !!!
Sumit Malik
 
Dharmendra Sable
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sumit,
Now I got what you are saying :-)
I was bit confused. I think Jeff can achieve his objectives with that.

Cheers,
Dharmendra.
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been able to achieve the results I needed. I think the fact that I needed to pass custom parameters to a constructor signaled a problem in my design. The old design was not efficiently using EJBs for scalability purposes. I have reworked my design based on your suggestions and now use the default constructor and pass the necessary parameters in the business methods.

Thanks for all of the help.
Jeff
 
You can thank my dental hygienist for my untimely aliveness. So tiny:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic