Invoking DAO from session bean
Hi,
I have a session bean method "method1" that invokes a DAO method which reads/write to DB2 database table. Will the DAO's db interaction will be part of the transaction initiated by container which is defined at the session bean's method ?
If yes, then will the transaction manager put a lock on the db record till the excution of the method is completed(transaction has a method scope), though the db read(DAO invocation) is at the beginning of the method ?
Thanks for your reply. But why do you feel that the container is not responsible for putting the lock as we set the transaction isolation level setting at the method level ?
The following problem led me to post my original question :
I have an application which used to run on WAS 5.0 and DB2 ver 7 patch 6 . I put a patch 10a for the DB2 drivers. After that I am getting problem executing a particular scenario. The scenario is - I have a stateless session bean method which updates a db record by invoking the an entity bean (CMP) and then accesses the same record through a DAO. But the read fails as the db record is locked. The session bean method has a transaction attribute "TX_REQUIRED". As both the db operations are part of the same transaction, I fail to understand why there should be lock on db record for the second operation ?
Do you have any clue ?
Similar Messages
-
Problem invoking gogle web service from session bean
Hello
I have developed a Web-Client which consumes the google-WebService with Apache Axis. I have generated the corresponding classes with WSDL2Java and the client works without problems. A little code fragment from my client:
GoogleSearchService service = new GoogleSearchServiceLocator();
// Now use the service to get a stub to the Service Definition Interface (SDI)
GoogleSearchPort google = service.getGoogleSearchPort();
GoogleSearchResult googleSearchResult = google.doGoogleSearch(GOOGLE_KEY, // java.lang.String key
q.toString(), //java.lang.String q
0, // int start
10, // int maxResults
false, //boolean filter
"", // java.lang.String restrict
false, //boolean safeSearch
"lang_ja|lang_en", // java.lang.String lr
"UTF-8", // java.lang.String ie
"UTF-8"); // java.lang.String oeNow I have to put the Web-Client in a SessionBean. Therfore I defined the code of the web-client in a method and put it into a stateless session bean and wrote a client for the session bean. But when the session bean invokes the corresponding method for consuming the google web service, there always occurs the following error:
[java] Exception in thread "main" java.rmi.ServerError: Unexpected Error; nested exception is:
[java] java.lang.NoClassDefFoundError: GoogleSearch/GoogleSearchService
But I have definitely all necessary classes in my classpath, like GoogleSearchService, etc. So all necessary classes are available. And the code to conume the web service als works because as said I tested it with a web-client.
Has anybody an idea what went wrong here? Is there anything important when I a web service is invoked by a session bean??:(
regards
patHas nobdy an idea?? :(( I tried for such a long time but I was not able to fix this problem....:(
Please help... -
How to call a EJB method from Session bean method
Hi all,
I'm new to J2EE programming. I have a simple doubt .
I have already created a lookup method for EJB bean in Session bean .
My question is how to call a method of an ENTITY bean (say insertRow) from SESSION bean method(Say invoke_insertRow) .
Please provide me an example code .
Thanks in advance.InitialContext ctx = new InitialContext();
GeneralEditor editor = (GeneralEditor) ctx
.lookup("GeneralEditorBean/remote");
GeneralService service = (GeneralService) ctx
.lookup("GeneralServiceBean/remote");
LanMu lm = new LanMu();
lm.setName("shdfkhsad");
editor.add(lm); -
How to send message to MessageDrivenBean from Session bean in JDeveloper
HI I am trying to write a sample program using JDeveloper.
I am trying to do these steps
1) client class which gets Session bean and calls its method.
2) write Stateless Session bean with a method which gets MDB and sends message.
3) write Message Driven Bean ( which prints message recieved from Session bean )
Set up
=======
jms.xml
{JDevHome}\jdev\system9.0.5.2.1618\oc4j-config\jms.xml : changed jms.xml file and included
<topic name="Demo Topic" location="jms/theTopic">
<description>A dummy topic</description>
</topic>
<topic-connection-factory name="Demo Topic Connection Factory" location="jms/theTopicConnectionFactory">
<description>A dummy topic connection factory</description>
</topic-connection-factory>
orion-ejb-jar.xml:
edited MDB entry to
<message-driven-deployment name="MessageLogger"
destination-location="jms/theTopic" connection-factory-location="jms/theTopicConnectionFactory">
</message-driven-deployment>
Implementation
===============
In client class:
I am getting session bean like
Properties props = System.getProperties();
props.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY , "com.evermind.server.rmi.RMIInitialContextFactory");
props.put( javax.naming.Context.SECURITY_PRINCIPAL , "admin" );
props.put( javax.naming.Context.SECURITY_CREDENTIALS,"welcome");
props.put( javax.naming.Context.PROVIDER_URL ,"ormi://localhost:23891/current-workspace-app");
Context ctx = new InitialContext(props);
MySessionHome home = (MySessionHome)
javax.rmi.PortableRemoteObject.narrow(obj, MySessionHome.class);
This part works fine, and I am calling method on session bean created out of home.
In Session bean:
I want to get TopicConnectionFactory and tried these two ways:
a)
getting the context by setting new environemnt values like
Properties props = System.getProperties();
props.put( javax.naming.Context.INITIAL_CONTEXT_FACTORY , "com.evermind.server.jms.EvermindConnectionFactory");
props.put( javax.naming.Context.SECURITY_PRINCIPAL , "admin" );
props.put( javax.naming.Context.SECURITY_CREDENTIALS,"welcome");
props.put( javax.naming.Context.PROVIDER_URL ,"ormi://localhost:9227/current-workspace-app");
Context ctx = new InitialContext( props);
When I try this,it is complaining that it cannot instantiate EvermindConnectionFactory.
I am not sure which factory class we have to use here.i tried all the Factory class in that package.but didn't worked.
next I used,
b)
tried to use default context in session bean to get MDB factory
String TOPIC_NAME="jms/theTopic";
String TOPIC_CONNECTION_FACTORY="jms/theTopicConnectionFactory";
TopicConnectionFactory connectionFactory = (TopicConnectionFactory)new InitialContext().lookup("java:comp/env/" + TOPIC_CONNECTION_FACTORY);
this gives
04/06/13 23:46:09 javax.naming.NameNotFoundException: jms/theTopicConnectionFactory not found in MySession
04/06/13 23:46:09 at com.oracle.naming.J2EEContext.getSubContext(J2EEContext.java:93)
this may be because JMS server runs on different port than other EJBs and have different namespaces.
Can any body give info,how we can make use of Message Driven bean from a Session Bean or from a JSP page or from a simple class inside JDeveloper.
Thanks in advance.
gopalHi,
There are some hints in this forum for how to do this.
I put together and make it working.
This example creates an MD Bean and have a simple message and a client class send messages to that bean.
Steps
=====
1)
a)in {JDev Home}\jdev\system9.0.5.2.1618\oc4j-config\jms.xml
<topic name="Demo Topic" location="jms/demoTopic">
<description>A dummy topic</description>
</topic>
<topic-connection-factory name="Demo Topic Connection Factory" location="jms/theTopicConnectionFactory">
<description>A dummy topic connection factory</description>
</topic-connection-factory>
b) in current project in orion-ejb-jar.xml
go to orion-ejb-jar properties and add these values there to MDB node
destination-location=jms/demoTopic
connection-factory-location=jms/theTopicConnectionFactory
2) create a dummy session bean and a dummy client for that session bean
This sets default configuration for the client application we write
doing so we do not need to set properties to get Initial context.It makes use of
{JDev Home}\jdev\system9.0.5.2.1618\oc4j-config\.client\jndi.properties
We can directly get Contexxt ctx = new InitialContext();
3) Create MDB and put this sample code in method
onMessage()
TextMessage tm = (TextMessage) msg;
try {
String text = tm.getText();
System.err.println("Received new message : " + text);
catch(JMSException e) {
e.printStackTrace();
4) go to properties for the MDB and set Destination to Topic
5) write Client code
Context ctx =new InitialContext();
// 1: Lookup ConnectionFactory via JNDI
TopicConnectionFactory factory =
(TopicConnectionFactory) ctx.lookup("jms/theTopicConnectionFactory");
// 2: Use ConnectionFactory to create JMS connection
TopicConnection connection = factory.createTopicConnection();
// 3: Use Connection to create session
TopicSession session = connection.createTopicSession( false, Session.AUTO_ACKNOWLEDGE);
// 4: Lookup Desintation (topic) via JNDI
Topic topic = (Topic) ctx.lookup("jms/demoTopic");
// 5: Create a Message Producer
TopicPublisher publisher = session.createPublisher(topic);
// 6: Create a text message, and publish it
TextMessage msg = session.createTextMessage();
msg.setText("This is a test message from My Test Client!!! .");
publisher.publish(msg);
6) Run the server and run the client -
URGENT ! JDEV 10.1.2 Problem with data control generated from session bean
I got a problem with data control generated from session bean which return a collection of data transfer object.
The dto's seem to be correct. The session bean load correctly the data into and the object's are plenty of data. Using the console to display the dto content is ok.
When generating a data control from this session bean and associate the dto included in the collection only the first object level and one-to-one dto object are correctly setted in the data control. Object that represent collection into the dto (one-to-many foreign key) are setted as collection with an iterator but the structure of the object is not setted. I don't know how to associate this second level of collection with the dto bean class to obtain the attributes definition.
I created a case with hr schema like the hrApp demo application in the tutorial with departments and employees table. I got the same problem.
Is it a bug ?
It exists a workaround to force the data control to understand the collection data structure ?
Help is welcome ! this is urgent !!!we found the problem by assigning the child dto bean class to the node representing the iterator in the xml file corresponding to the master dto.
-
Problem while invoking a Stateless Session bean from another bean
Hi,
I have a peculiar problem while coding with Stateless Session beans. Maybe you guys can help me out over here. The scenario is as follows
There are 3 Stateless Session beans. Let Us say Bean A, B and C. There are three methods, method1, method2, and method3 inside A, B and C respectively.
From A.method1(), B.method2(), and C.method3() are being invoked sequentially. Each of these methods does some JDBC operation and then returns.
The problem is this, if C.method3() throws and exception, then I am unable to rollback the changes made by B.method2(). Those changes get "Committed" to the database.
All the 3 beans have Bean managed persistence property set. I am using WebSphere 6.1.
Any insight on why this is happening would be greatly appreciated.
Thanks In Advance
Amardeep VermaHi,
This is a matter of calling all three methods in the same transaction context. Most easy way of doing this is having a 4th session bean containing a method calling the other 3. Make sure that the Transaction Attributes are REQUIRED, which is the default.
If the calls a to different backends/databases, you need global transactions and therefor XA complient database and drivers.
HTH Robert -
Can I invoke Sockets in Session beans
My server which is Jboss, needs to invoke a method on one of its clients, the call is not comming from the client. All that the server know's is the IP address of the Client. can a server invoke that client by calling a socket routine in one of the sessions beans.
are there is a better solution for this problem.
Help needed ...
Nas.Calling sockets is not against the EJB spec. Using ServerSocket is against the specification because the socket can block and thus does not allow the EJB to passivate properly.
Using sockets or RMI from a session bean is perfectly legal and not problematic. You just have to make sure that you do the proper things in the ejbActivate and ejbPassivate methods.
Paul -
Direct DB access from Session Bean w/o using Serialized Objects
I am developing a system where I am receiving some messages (data ) inside session bean and I want to log that data into data base �.i.e inserting that data in to various tables. I am not showing that data to client ( that is taken care by another application).
So I am directly calling insert methods on various tables instead of going for serialized classes for each of that tables and calling setter methods. Is this approach correct? Or this will create nightmares when millions of messages are to be logged? Do I have to make serialized objects? Please post the suggestions ..Thank you in advance.
If session bean is making direct inserts in the DB using Helper classes as shown below �is there any problem of concurrency?? Means multiple session bean instances inserting data in the same table using the helper class will create any problems?? I am using MySql db presently. Or all will work fine coz I am using the data source and pool available in welogic app server?
Is this a good approach if my application is doing inserts 90% of times? or I have to use entity beans or serialized objects encapsulating each class?
public class Logger implements SessionBean
DAO dao = getDAO();
dao.insertXyzLog(�x�, �y�,�.);
private DAO getDAO(){
if(Dao == null) {
oao = DAOFactory.getDAO();
return Dao;
//other std methods
public interface DAO {
// methods to directly insert data in to the tables
//some methods to look for required value in another tables
public abstract void insertXyzLog (String x, Stringy, ���.);
public class DAOImpl implements DAO {
// look up for JNDI data sourse
//method to return connection
public void insertXyzLog (String x, Stirng y�){
//SQLs for inserting into Xyz table using connection obtained above.Hi,
Nothing wrong in using Helper class to insert into table. It won't create problem as long as your database server able to handle that many request from client.
If you use weblogic server and datasource, the server will take care of all connection pool management depending upon your configuration parameters.
Moreover, insert won't lock the table. So you need not worry about those things.
Best Luck,
Senthil Babu
Developer Technical Support
SUN Microsystems
http://www.sun.com/developers/support/ -
Obtaining PersistenceManager from Session Bean in JBoss 3.0.4
Hi,
I'm attempting to use the JCA for JBoss with Kodo 2.4.0. The kodo.rar seems to deploy ok:
2002-12-18 11:19:43,640 INFO [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] Bound connection factory for resource adapter 'KodoJDO' to JNDI name 'java:/kodo'
2002-12-18 11:19:43,640 INFO [org.jboss.resource.connectionmanager.LocalTxConnectionManager] Started
2002-12-18 11:19:43,640 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/kodo.rar
In my session bean, I access the PersistenceManager using the following code:
InitialContext context _ new InitialContext();
JDOConnectionFactory factory _ (JDOConnectionFactory)context.lookup("java:/kodo");
PersistenceManager pm _ (PersistenceManager)factory.getConnection();
The code generates a JDOFatalDataStoreException when I try to execute it:
Error in use of ManagedConnectionPool: matchManagedConnection failed with subject: null and ConnectionRequestInfo: [email protected]3be7ac; - nested throwable: (javax.resource.ResourceException: Error in use of ManagedConnectionPool: matchManagedConnection failed with subject: null and ConnectionRequestInfo: [email protected]3be7ac)
And when I execute it a second time around, it seems to retrieve the PersistenceManager ok, but when I try to invoke methods on it, I get an SQLException:
Connection is broken: Software caused connection abort: socket write error
at com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.newDataStoreId(JDBCStoreManager.java:464)
at com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistentFilter(PersistenceManagerImpl.java:1107)
at com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistent(PersistenceManagerImpl.java:1059)
at org.aims.his.ejb.PatientBean.createPatient(PatientBean.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
... 47 more
So...what did I miss? Could it be the configuration of my connection to the database in kodo-service.xml (see attached)? In the server log files I didn't see any of my connection properties.
Any help is appreciated.
Thanks,
JeffOk, looks like it was the kodo-service.xml file. I removed the ConnectionFactoryName entry and most of the options were commented out which I didn't catch...
Thanks,
Jeff
"Jeff Carnegie" <[email protected]> wrote in message news:[email protected]...
Hi,
I'm attempting to use the JCA for JBoss with Kodo 2.4.0. The kodo.rar seems to deploy ok:
2002-12-18 11:19:43,640 INFO [com.solarmetric.kodo.impl.jdbc.ee.ManagedConnectionFactoryImpl.kodo] Bound connection factory for resource adapter 'KodoJDO' to JNDI name 'java:/kodo'
2002-12-18 11:19:43,640 INFO [org.jboss.resource.connectionmanager.LocalTxConnectionManager] Started
2002-12-18 11:19:43,640 INFO [org.jboss.deployment.MainDeployer] Deployed package: file:/C:/jboss-3.0.4_tomcat-4.1.12/server/default/deploy/kodo.rar
In my session bean, I access the PersistenceManager using the following code:
InitialContext context _ new InitialContext();
JDOConnectionFactory factory _ (JDOConnectionFactory)context.lookup("java:/kodo");
PersistenceManager pm _ (PersistenceManager)factory.getConnection();
The code generates a JDOFatalDataStoreException when I try to execute it:
Error in use of ManagedConnectionPool: matchManagedConnection failed with subject: null and ConnectionRequestInfo: [email protected]3be7ac; - nested throwable: (javax.resource.ResourceException: Error in use of ManagedConnectionPool: matchManagedConnection failed with subject: null and ConnectionRequestInfo: [email protected]3be7ac)
And when I execute it a second time around, it seems to retrieve the PersistenceManager ok, but when I try to invoke methods on it, I get an SQLException:
Connection is broken: Software caused connection abort: socket write error
at com.solarmetric.kodo.impl.jdbc.runtime.JDBCStoreManager.newDataStoreId(JDBCStoreManager.java:464)
at com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistentFilter(PersistenceManagerImpl.java:1107)
at com.solarmetric.kodo.runtime.PersistenceManagerImpl.makePersistent(PersistenceManagerImpl.java:1059)
at org.aims.his.ejb.PatientBean.createPatient(PatientBean.java:117)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at org.jboss.ejb.StatelessSessionContainer$ContainerInterceptor.invoke(StatelessSessionContainer.java:660)
at org.jboss.resource.connectionmanager.CachedConnectionInterceptor.invoke(CachedConnectionInterceptor.java:186)
at org.jboss.ejb.plugins.StatelessSessionInstanceInterceptor.invoke(StatelessSessionInstanceInterceptor.java:77)
at org.jboss.ejb.plugins.AbstractTxInterceptor.invokeNext(AbstractTxInterceptor.java:107)
at org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.java:178)
at org.jboss.ejb.plugins.TxInterceptorCMT.invoke(TxInterceptorCMT.java:60)
at org.jboss.ejb.plugins.SecurityInterceptor.invoke(SecurityInterceptor.java:130)
at org.jboss.ejb.plugins.LogInterceptor.invoke(LogInterceptor.java:204)
... 47 more
So...what did I miss? Could it be the configuration of my connection to the database in kodo-service.xml (see attached)? In the server log files I didn't see any of my connection properties.
Any help is appreciated.
Thanks,
Jeff -
Generating web service from session bean
Hi
I have a session bean in one project which has a service-endpoint defined.
My web services are in another project entirely, within the same workspace if that helps any.
When I generate the web service from the EJB JDev turns the business tier project into a web project,
I don't see any options to include the web service in the web project.
I've reversed all of the changes, but wonder if I shouldn't redo it and copy the mapping file and configuration
across to the web project and reverse the changes in the business tier.
This is a workaround that I'm hoping to avoid, as I'm doing the "howto" for this in our project.
How is this normally done?I tried generating the web servioce from WSDL, in the web project.
I tested and the web service works fine.
Then I changed the config file to point to the ejb, but the server won't start up....
*08/09/17 10:58:40 WARNING: Application.setConfig Application: current-workspace-app is in failed state as initialization failed.*
This is the webservices.xml bit I updated...
<ejb-link>SomeOrOtherEjbName</ejb-link> The bit I found in webservices.xml when the service is in the business tier.
<!-- <servlet-link>SomeOrOtherWebServiceSoapHttpPort</servlet-link> --> The service that works in the web tier. -
Calling stored procedure from session bean method
I have a situation like this :
I have one method on a stateless session bean (and I mark this method as container managed transaction). For database related stuff, I am not using entity beans, I am using my own layer of OR mapping. This method does a lot of stuff and it involves many trips to the database, as a result of which the performance is very poor. I have identified certain pieces of functionality from this method which I think can be moved to stored procedures, while some of the functionality can still remain in the session bean method. So my scenario is like this :
session bean method start
store some data in tables(using my OR layer)
call the stored procedure
session bean method end
My question is :
Will the data that I am storing in tables from within the session bean method, be available to the code executing inside stored proc.
secondly, how do I sync the transcation which is being initiated by the container with the transaction under which the stored proc is executing or is it that the stored procedure code will also be executing under the container managed transcation.
Thanks
VimalHi Vimal,
Will the data that I am storing in tables from within
the session bean method, be available to the code
executing inside stored proc.There's only one way to find out (isn't there?)
secondly, how do I sync the transcation which is
being initiated by the container with the transaction
under which the stored proc is executing or is it
that the stored procedure code will also be executing
under the container managed transcation.Again, why not just "suck it and see!"
[Or is there some reason why you can't?]
As I interpret the EJB specification, if the transaction attribute for your session bean method is such that it starts a transaction, then that transaction will be terminated when the method completes -- and every operation that occurs within the framework of that method will be in the one transaction.
In other words, your database stored procedure should execute within the same transaction as your O/R mapping layer.
However, how OC4J behaves may not exactly follow what is written in the (EJB) specification. Hence I repeat, "try it and see for yourself".
Put it this way: as far as I know, the only way that your stored procedure would NOT see the changes made by your O/R mapping layer is if they both executed in separate transactions and the O/R mapping layer did not commit its changes before the stored procedure began its execution.
Hope this has helped.
Good Luck,
Avi. -
Problem while invoking popup from backing bean
I am invoking a popup from backing bean method.
The same backing bean method has the business logic which depends on the data collected from popup(user enters some data on popup).
So I need the business logic to be executed after popup comes up.
The popup is coming after the execution of return statement in backing bean method . How do i make popup trigger at earlier point in the method.
<af:commandToolbarButton text="#{corePostupgradeuiBundle.SIGN_OFF_MIG}"
id="socb52"
partialSubmit="true"
actionListener="#{viewScope.signoffBean.signOffAgents}"
partialTriggers="t3"/>
public void signOffAgents(ActionEvent event) throws SQLException {
DCBindingContainer bc =
(DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding summaryIter =
bc.findIteratorBinding("Signoff1Iterator");
showPopup("credentials"); //will get credential details from user and store in credential Bean
//Following logic uses the data collected from popup
EMCredentialReference credRef= credentialBean.getCredReference();
submitJOb(credRef);
public static void showPopup(String popupId) {
FacesContext context = FacesContext.getCurrentInstance();
StringBuilder script = new StringBuilder();
script.append("AdfPage.PAGE.findComponent(\"").append(popupId).append("\").show();");
ExtendedRenderKitService erks =
Service.getService(context.getRenderKit(),
ExtendedRenderKitService.class);
erks.addScript(context, script.toString());
UIComponent component = context.getViewRoot().findComponent(popupId);
RequestContext.getCurrentInstance().addPartialTarget(component);
}Well, your work flow is wrong.
What you try to accomplish should work out of the box as
1) user hit toolbar button
2) this opens a popup "credentials" which have listeners for ok and cancel
3) use fills in data in popup and hit ok or cancel
4) one of the listeners gets fired
5a) if OK listener you do your business logic
5b) if cancel you do something else
So all you have to do is the use a af:af:showPopupBehavioron the toolbar button, add a popup canel listener (if you need to act on canel) dependign on your popup design (dialog or simple button) add the appropriate listeners and in the listener method so your business logic.
Timo -
Database access from session bean
Hello,
I have a stateless session bean which performs some complex
calculations, and also does some database access.
For the database access the bean class has a datasource as
follows:
public class TestBean implements SessionBean {
private DataSource ds_;
public void ejbCreate() {
getDataSources();
private void getDataSources() {
try {
Context ictx = new InitialContext();
ds_ = (DataSource)ictx.lookup("java:comp/env/jdbc/TestDB");
} catch (Exception e) {
e.printStackTrace();
throw new EJBException(e);
Now this class has a method (which is also in the remote interface)
calculateSomething(). This method constructs a number of other
objects that do the actual calculation, and one of these objects
does the actual database access. How would another object be able to
use the datasource that was constructed in the bean class?
I could pass the datasource reference to that object, but that would
break my encapsulation. This is because that object does not get
created directly by the bean object, but rather the way the objects
interact is something like A -> B -> C, where A is the TestBean, and
C is the object that does the DB access. If I passed the datasource,
I would need to make B aware of the datasource, which doesn't
seem good design, because B doesn't do any database access.
Alternatively I could do the lookup in class C, but that would
degrade the performance, as an object C gets created and destroyed
every time the calculateSomething() method is called.
A third option I have thought of, is to add a public method to the
bean that returns a connection. Whenever another object gets
created, a reference to the bean object will be passed along. Then,
if another object needs to do database access, it will call back
the bean to get a connection. This seems just as bad (if not worse)
than the first option.
Does anyone have an elegant solution for this situation? What is
the best practice of handling datasources when a bean class doesn't
do the database access itself? In all the examples I've seen so far,
all the functionality was in the session bean class, but again that
doesn't seem good OO design, and would result in a single huge class.
regards,
KostasThanks again to both for the replies. Here are my responses:
Yi Lin: Yes, I know that an entity bean would solve this problem, however it has been decided not to use entity beans so this is not my call (I think the reason entity beans are not allowed in this project is that they are considered risky: there are other applications that access the same database, so if the container caches entity bean data as you describe, then the users might get inconsistent results).
Gerard: Actually object B is the one that has the business logic and C is a peer object that only does database access and no calculaitons. For example B can be Customer, and C CustomerDB. This is why object B does not have any knowledge of datasources or connections. So my design does not appear to be that bad!
As far as the factory you propose is concerned, I cannot understand how this would solve my problem. In order to solve this situation the factory would need to be persistent, i.e. get created by the ejbCreate() method, and destroyed whenever the container decides to destroy the bean. There would be no point in object C creating the factory, as I would have the overhead of doing the JNDI lookup every time I create a C.
So the question remains the same: how would I pass a reference to the factory from A to C without making B aware of it? -
Calling Data Control from Session bean
Is it possible to use workshop data control from with in Session bean.
If the client code is located in the same "deployment unit" (e.g. EAR
file) as the EJBs, then you can pass the data by reference.
Serialization is required when crossing between deployment units. This
is required to support redeployment.
Hyung-Jin Kim wrote:
I recently downloaded WL6.0 and I noticed that when a
session bean returns data to its client, the data is
always serialized back the client -- EVEN it the client
is on the same machine. Ideally, I would prefer that a
reference to the data simply be returned to the client.
Does the serialization occur because WL6.0 put session
beans in its own ClassLoader or does the serialization occur
because of the way WL6.0 compiles the RMI stubs? Thanks
for your response.
-hjk -
NoSuchObjectException from Session bean wrapper
Hi,
I am getting the following exception when accessing a session bean.
The exception is thorwn from a method of a statful session bean. The lines before and after the particular line are exceuted properly
public void cloneBasket(eprcBasketSF pDestinationBkt) throws RemoteException{
pDestinationBkt.setIsJobValid(this.m_IsBktJobValid);
pDestinationBkt.setIsAppValid(this.m_IsBktAppValid);
pDestinationBkt.setIsSubValid(this.m_IsBktSubValid);
pDestinationBkt.setIsPOValid(this.m_IsBktPOValid);
pDestinationBkt.setIsEdaValid(this.m_IsBktEdaValid);
pDestinationBkt.setIsIdaValid(this.m_IsBktIdaValid);
//** Exception is thrown at this line only
pDestinationBkt.setBasketLines(this.m_bktLines);
pDestinationBkt.setDeletedBasketLines(cloneDeletedBasketLines());
java.rmi.NoSuchObjectException: Session has timed out
at com.evermind.server.ejb.StatefulSessionEJBObject.throwPassivisationEx
ception(.:215)
at eprcBasketSF_StatefulSessionBeanWrapper3.cloneBasket(eprcBasketSF_Sta
tefulSessionBeanWrapper3.java:469)
at com.comp.eProcurement.eprcCore.eprcBasketJBean.cloneBasket(eprcBaske
tJBean.java:58)
at com.comp.eProcurement.eprcCore.eprcBasketTemplateManager.retrieveBas
ketByKey(eprcBasketTemplateManager.java:1471)
at com.comp.eProcurement.eprcCore.eprcBasketTemplateManager.getCurrentB
asket(eprcBasketTemplateManager.java:598)
at com.comp.eProcurement.eprcCore.eprcEprocSession.passivate(eprcEprocS
ession.java:953)
We are using orion server 1.5.3. Can any body tell me what could be causing this problem.
Thanks in advance
karthiHi,
I got an exact same error. I'm using Oracle 9i App Server, but it's based on Orion server, which you're using.
When I try to use stateful session bean, I also got "Session has timed out" error at the exact same point (com.evermind.server.ejb.
StatefulSessionEJBObject.throwPassivisationException).
I have no clue, either. My session bean worked fine bofore, but after I updated records in the database, then something went wrong. First, I thought database connection problem or something, but it's definitely not.
If you find out the problem, please post it here or send me email below.
[email protected]
If I figure it out, I'll post it here, too.
thanks.
-tom
Maybe you are looking for
-
No sound in iMovie 3.03
Running iMovie 3.03 in OS 10.4.6 and all is well except for sound. Songs play in iTunes, iMovie claims to add songs to project, but when play back.... no sound. Boxes on right all checked, volume at 100%. Cannot find iLife DVD to re-install. Any sugg
-
Hi, 1's we complete the AS-IS Document and we have interactions withthe concerned modules how do we map the Process in to SAP.how do we create COPst Centre's Thanks, PM
-
PS CS6 auf neuem Computer installieren.
Hey, ich möchte mir einen neuen Computer zulegen. Hier auf dem alten Computer habe ich CS6 schon installiert. Dazu bekam ich (wie wir alle) eine Seriennummer. Kann ich diese Seriennummer für die Installlation auf meinem neuen Computer verwenden oder
-
Hi I am using EyeTV to record VHS tapes (PAL) to my mac then using toast to burn them to DVD. Now, I just burnt a DVD and when I put it in my DVD player the picture works, but there is no sound. When I run it in my mac however, it is fine--I get soun
-
Problems with iWeb podcast at dot.mac
One of my PC/Windows XP friends can't play audio from my podcast created in Garageband & iWeb at dot.mac. QT will not open. He has the latest version of QT for Windows and no ISP problems that I know of. The files are quite big but fine with Mac OSX