Does Entity Bean allows Programmatic Transactions.
Hi,
I would like to know whether Entity beans allows Programmatic transactions. If they are not allowing then, if we want to abort the transactions then how we can do that.
Regards,
Satish. G
In case ur application throws runtime exception u need not worry about aborting the transaction. container takes care. suppose based on some condition (or possibly application exception where container won't do rollback automatically) if u want to abort / rollback the transaction you can call setRollbackOnly() of EntityContext which informs the container not to commit the transaction
- Paul
Similar Messages
-
Hi,
I have created two bean managed entity beans, User and Role, abstracting users
and groups in a ldap base. A User may have more than one Role. This is represented
by a (bean managed) 1:many relationship directed from User to Role. For some weird
reasons I get a transaction rollback when reading data, when transactions are
turned on (REQUIRED).
While we where running WLS 6.1 sp1 we had no problems with this as we could set
transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
EJB spec, but containers may support it and obviously WLS used to do just that.
I have not seen any change in the release notes of sp2 that indicates that this
behaviour has changed.
Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
in sp2?
If anybody are curiuos or have any good ideas, the stacktrace I get is:
javax.ejb.TransactionRolledbackLocalException: EJB Exception:
- with nested exception:
[javax.ejb.EJBException
- with nested exception:
[weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
[java.util.ConcurrentModificationException]]]
Start server side stack trace:
java.rmi.RemoteException: EJB Exception: ; nested exception is:
javax.ejb.TransactionRolledbackLocalException: EJB Exception:
- with nested exception:
[javax.ejb.EJBException
- with nested exception:
[weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
[java.util.ConcurrentModificationException]]]
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
at java.util.LinkedList$ListItr.next(LinkedList.java:476)
at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
Any kind of help would be appreciated:)
Regards,
Brynjar GlesnesWLS support NotSupported on Entity Beans.
It looks like you've hit a bug in the EJB container where an internal Collection class has been modified while the
container is running through an iterator on it.
You should open a case with [email protected]
-- Rob
Brynjar Glesnes wrote:
Hi,
I have created two bean managed entity beans, User and Role, abstracting users
and groups in a ldap base. A User may have more than one Role. This is represented
by a (bean managed) 1:many relationship directed from User to Role. For some weird
reasons I get a transaction rollback when reading data, when transactions are
turned on (REQUIRED).
While we where running WLS 6.1 sp1 we had no problems with this as we could set
transaction to NOTSUPPORTED for these two EJBs. Due to other hickups we had to
upgrade to sp2 and suddenly the error reappears leading me to believe that NOTSUPPORTED
isn't allowed anymore by the WLS. I know that NOTSUPPORTED isn't required by the
EJB spec, but containers may support it and obviously WLS used to do just that.
I have not seen any change in the release notes of sp2 that indicates that this
behaviour has changed.
Does anybody know if WLS really doesn't support NOTSUPPORTED for enity beans anymore
in sp2?
If anybody are curiuos or have any good ideas, the stacktrace I get is:
javax.ejb.TransactionRolledbackLocalException: EJB Exception:
- with nested exception:
[javax.ejb.EJBException
- with nested exception:
[weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
[java.util.ConcurrentModificationException]]]
Start server side stack trace:
java.rmi.RemoteException: EJB Exception: ; nested exception is:
javax.ejb.TransactionRolledbackLocalException: EJB Exception:
- with nested exception:
[javax.ejb.EJBException
- with nested exception:
[weblogic.transaction.RollbackException: Unexpected exception in beforeCompletion:
sync=weblogic.ejb20.internal.TxManager$TxListener@1c2906 - with nested exception:
[java.util.ConcurrentModificationException]]]
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodification(LinkedList.java:535)
at java.util.LinkedList$ListItr.next(LinkedList.java:476)
at weblogic.ejb20.manager.DBManager.beforeCompletion(DBManager.java:370)
at weblogic.ejb20.internal.TxManager$TxListener.beforeCompletion(TxManager.java:481)
at weblogic.transaction.internal.ServerSCInfo.callBeforeCompletions(ServerSCInfo.java:551)
at weblogic.transaction.internal.ServerSCInfo.startPrePrepareAndChain(ServerSCInfo.java:88)
at weblogic.transaction.internal.ServerTransactionImpl.localPrePrepareAndChain(ServerTransactionImpl.java:980)
at weblogic.transaction.internal.ServerTransactionImpl.globalPrePrepare(ServerTransactionImpl.java:1504)
at weblogic.transaction.internal.ServerTransactionImpl.internalCommit(ServerTransactionImpl.java:216)
at weblogic.transaction.internal.ServerTransactionImpl.commit(ServerTransactionImpl.java:190)
at weblogic.ejb20.internal.BaseEJBLocalObject.postInvoke(BaseEJBLocalObject.java:207)
at com.takecargo.domainentities.role.RoleBean_1ipw6_ELOImpl.getName(RoleBean_1ipw6_ELOImpl.java:86)
at com.takecargo.domainentities.role.RoleConverter.getVOforRoleLocal(RoleConverter.java:51)
Any kind of help would be appreciated:)
Regards,
Brynjar Glesnes -
Use direct JDBC with CMP entity bean in one transaction
I am trying to use direct JDBC call with CMP entity bean within a session
bean method that requires transaction. The problem is that it appears these
are not in the same transaction. When I use the JDBC call, the CMP entity
bean update to the DB has not been committed yet.
We are using Weblogic 5.1 SP6. The DB is Oracle.
What I do for the JDBC is get a new connection from the pool using weblogic
jdbc pool driver.
Any help would be appreciated.
PatrickHi. You can do JDBC and invoke CMP EJBs and have this all treated
as one transaction, if your hand-written code explicitly starts
a JTS transaction, then uses the jts driver or a TxDataSource to
get the JDBC connection. Then your code can call transactional
EJBs and their work will be included in the transaction you started.
Assuming the bean work went OK, and your manual JDBC went OK, you
can manually commit the UserTransaction at that time. This is 5.1
talk. For 6.0, with @PC, this may be even easier...
Joe
Patrick Shen wrote:
>
But if I do that, then they would not be in the same transaction anymore.
Is there any way to use JDBC with CMP Entity bean in the same transaction?
Patrick
"L'artiste" <[email protected]> wrote in message
news:[email protected]...
Are you calling all the CMP create in the session Bean ? If so, beforeyou
make the JDBC call from the session bean, the CMP in 2. should commit. Try
to set its attribute to TX_REQUIRES_NEW. This way, the calling client will
block until this transaction is done (committed) before the execution
continues. There might be some overhead involved in doing so if you are
anticipating a lot of users.
"Patrick Shen" <[email protected]> wrote in message
news:[email protected]...
What I am trying to do is:
In a Session bean method -
1. create a new CMP entity bean (a new row in DB table)
2. create another new CMP entity bean that uses previous bean as foreignkey
3. use JDBC to update the row just created
And all these 3 calls have to be in one transaction.
Thanks,
Patrick
"L'artiste" <[email protected]> wrote in message
news:[email protected]...
Can you give a little bit more information?
Do you have methods in your session bean that creates this CMP entitybeans?
It looks like
you might wanna try to change the isolation level to
TRANSACTION_READ_COMITTED
to preven dirty_read.
"Patrick Shen" <[email protected]> wrote in message
news:[email protected]...
I am trying to use direct JDBC call with CMP entity bean within a
session
bean method that requires transaction. The problem is that it
appears
these
are not in the same transaction. When I use the JDBC call, the CMP
entity
bean update to the DB has not been committed yet.
We are using Weblogic 5.1 SP6. The DB is Oracle.
What I do for the JDBC is get a new connection from the pool usingweblogic
jdbc pool driver.
Any help would be appreciated.
Patrick
PS: Folks: BEA WebLogic is expanding rapidly, with both entry and advanced positions
for people who want to work with Java, XML, SOAP and E-Commerce infrastructure products.
We have jobs at Nashua NH, Liberty Corner NJ, San Francisco and San Jose CA.
Send resumes to [email protected] -
Hi, I use the version 9.0.4.0.0
If I give an entity bean transaction type supports... what will be the actual transaction type when the bean is deployed....
So far I know the container does not suppert the tranaction type supports...
From
Oracle® Application Server Containers for J2EE
Enterprise JavaBeans Developer’s Guide
10g (9.0.4)
All entity beans with CMP and CMR relationships must be involved in a
transaction. As such, you cannot define any entity bean with a transaction attribute
of NEVER, SUPPORTS, or NOT_REQUIRED as this would put the entity outside of
a transaction.
But I can still deploy an entity bean with transaction type set to supports....
KrisIn the deployment descriptor file set the trasaction isolation level as TransactionReadUncommitted. It should solve your issue.
-
We have a rather large system where we get a lot of transactions. To
tune our system we decided to turn off transaction support for some
beans. (by setting the transaction attribute to NotSupported).
The system did not decrease the amount of transactions run so we
started wondering what was going on.
To test this we first implemented a small test application and then
also tested some examples provided by weblogic. In both cases we came
to the conclusion that when using entity beans transactions are always
run. We tested with wl6.1 and wl6.1sp3
A short example of some code:
Client:
for (int i=0; i<numBeans; i++) {
accounts = findOrCreateAccount("ID: "+i, i * 1000);
//transfer 1000 from account 10 to account 11
try {
accounts[10].withdraw(1000);
accounts[11].deposit(1000);
} catch (ProcessingErrorException e) {
log(" could not xfer cash");
} catch (RemoteException e) {
log(" could not xfer cash");
AccountBean (Entity Bean)
public double deposit(double amount) {
log("Depositing $" + amount + " into '" + accountId + "'");
if (weblogic.transaction.TxHelper.getTransaction() == null) {
log("dep no transaction");
else {
log("dep tx:
"+weblogic.transaction.TxHelper.getTransaction().getXID());
balance += amount;
if(true) {
log("throwing EJB EXCEPTION FOR TESTING");
throw new EJBException();
return balance;
ejb-jar.xml
<container-transaction>
<method>
<ejb-name>beanManaged</ejb-name>
<method-intf>Remote</method-intf>
<method-name>deposit</method-name>
</method>
<method>
<ejb-name>beanManaged</ejb-name>
<method-intf>Remote</method-intf>
<method-name>withdraw</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
The first indication that a transaction was running was to check the
log:
deposit transaction: 370:971b99c458e3d95b
Then the transaction was rolled back and and we could see that the
account balance was unchanged which proves that a transaction was
running.
We can't be the first ones to discover this, but I can't find this
documented anywhere else.If an entity bean is called and no transaction is in effect, the container
will
always start a transaction for its own use. Its not expensive to start a
transaction in WLS. The best architecture is almost always to
begin/commit
transactions before calling entity beans and let the entity beans inherit
the transaction, so that multiple calls to an entity bean are grouped into
a single transaction.
Seth
Daniel Bernholc wrote:
We have a rather large system where we get a lot of transactions. To
tune our system we decided to turn off transaction support for some
beans. (by setting the transaction attribute to NotSupported).
The system did not decrease the amount of transactions run so we
started wondering what was going on.
To test this we first implemented a small test application and then
also tested some examples provided by weblogic. In both cases we came
to the conclusion that when using entity beans transactions are always
run. We tested with wl6.1 and wl6.1sp3
A short example of some code:
Client:
for (int i=0; i<numBeans; i++) {
accounts = findOrCreateAccount("ID: "+i, i * 1000);
//transfer 1000 from account 10 to account 11
try {
accounts[10].withdraw(1000);
accounts[11].deposit(1000);
} catch (ProcessingErrorException e) {
log(" could not xfer cash");
} catch (RemoteException e) {
log(" could not xfer cash");
AccountBean (Entity Bean)
public double deposit(double amount) {
log("Depositing $" + amount + " into '" + accountId + "'");
if (weblogic.transaction.TxHelper.getTransaction() == null) {
log("dep no transaction");
else {
log("dep tx:
"+weblogic.transaction.TxHelper.getTransaction().getXID());
balance += amount;
if(true) {
log("throwing EJB EXCEPTION FOR TESTING");
throw new EJBException();
return balance;
ejb-jar.xml
<container-transaction>
<method>
<ejb-name>beanManaged</ejb-name>
<method-intf>Remote</method-intf>
<method-name>deposit</method-name>
</method>
<method>
<ejb-name>beanManaged</ejb-name>
<method-intf>Remote</method-intf>
<method-name>withdraw</method-name>
</method>
<trans-attribute>NotSupported</trans-attribute>
</container-transaction>
The first indication that a transaction was running was to check the
log:
deposit transaction: 370:971b99c458e3d95b
Then the transaction was rolled back and and we could see that the
account balance was unchanged which proves that a transaction was
running.
We can't be the first ones to discover this, but I can't find this
documented anywhere else. -
Do JNDI look up for entity beans from a session bean in different jars
I have a problem doing entity beans JNDI look up from a session bean which is deployed
as a separate package (session.jar) from the entity beans (entity.jar)
I believe if both session bean and entity beans are deployed into one jar and
I specify ejb-local-reference-description for session bean, it should work. However,
due to some reason, they have to be in separated packages but still in the same
container. Then question how to do JNDI lookup given entity beans only have local
interfaces?
FYI.
1 both session.jar and entity.jar are self-contained. i.e., no deployment error.
each JNDI name can be viewed from JNDI tree
2. weblogic-ejb-jar.xml for session.jar
<weblogic-ejb-jar>
<description><![CDATA[Generated by XDoclet]]></description>
<weblogic-enterprise-bean>
<ejb-name>PetstoreLogic</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<reference-descriptor>
</reference-descriptor>
<jndi-name>PetstoreLogic</jndi-name>
<local-jndi-name>PetstoreLogicLocal</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
3. weblogic-ejb-jar.xml (code snip) for entity.jar
<weblogic-enterprise-bean>
<ejb-name>Account</ejb-name>
<entity-descriptor>
<persistence>
<persistence-type>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-type>
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
</persistence-use>
</persistence>
</entity-descriptor>
<reference-descriptor>
</reference-descriptor>
<local-jndi-name>net.sourceforge.cpetstore/AccountLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
4. if I do
accountLocalHome = (AccountLocalHome) ic.lookup("net/sourceforge/cpetstore/AccountLocalHome");
get error like:
javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException:
While trying to look up /app/ejb/net.sourceforge.cpetstore-entity.jar#Account/local-home
in /app/ejb/cpetstore-ejb.jar#PetstoreLogic.; remaining name '/app/ejb/net/sourceforge/cpetstore-entity/jar#Account/local-home'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:150)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338)In weblogic-ejb-jar.xml use jndi-name instead of local-jndi-name in reference-descriptor
element.
"Qiming He" <[email protected]> wrote:
>
I have a problem doing entity beans JNDI look up from a session bean
which is deployed
as a separate package (session.jar) from the entity beans (entity.jar)
I believe if both session bean and entity beans are deployed into one
jar and
I specify ejb-local-reference-description for session bean, it should
work. However,
due to some reason, they have to be in separated packages but still in
the same
container. Then question how to do JNDI lookup given entity beans only
have local
interfaces?
FYI.
1 both session.jar and entity.jar are self-contained. i.e., no deployment
error.
each JNDI name can be viewed from JNDI tree
2. weblogic-ejb-jar.xml for session.jar
<weblogic-ejb-jar>
<description><![CDATA[Generated by XDoclet]]></description>
<weblogic-enterprise-bean>
<ejb-name>PetstoreLogic</ejb-name>
<stateless-session-descriptor>
</stateless-session-descriptor>
<reference-descriptor>
</reference-descriptor>
<jndi-name>PetstoreLogic</jndi-name>
<local-jndi-name>PetstoreLogicLocal</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
3. weblogic-ejb-jar.xml (code snip) for entity.jar
<weblogic-enterprise-bean>
<ejb-name>Account</ejb-name>
<entity-descriptor>
<persistence>
<persistence-type>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
<type-storage>META-INF/weblogic-cmp-rdbms-jar.xml</type-storage>
</persistence-type>
<persistence-use>
<type-identifier>WebLogic_CMP_RDBMS</type-identifier>
<type-version>6.0</type-version>
</persistence-use>
</persistence>
</entity-descriptor>
<reference-descriptor>
</reference-descriptor>
<local-jndi-name>net.sourceforge.cpetstore/AccountLocalHome</local-jndi-name>
</weblogic-enterprise-bean>
4. if I do
accountLocalHome = (AccountLocalHome) ic.lookup("net/sourceforge/cpetstore/AccountLocalHome");
get error like:
javax.naming.LinkException: . Root exception is javax.naming.NameNotFoundException:
While trying to look up /app/ejb/net.sourceforge.cpetstore-entity.jar#Account/local-home
in /app/ejb/cpetstore-ejb.jar#PetstoreLogic.; remaining name '/app/ejb/net/sourceforge/cpetstore-entity/jar#Account/local-home'
at weblogic.jndi.internal.BasicNamingNode.newNameNotFoundException(BasicNamingNode.java:869)
at weblogic.jndi.internal.ApplicationNamingNode.lookup(ApplicationNamingNode.java:150)
at weblogic.jndi.internal.WLContextImpl.lookup(WLContextImpl.java:338) -
HI, does entity bean exsit in CE7.1 SR5? I can not find it.
Snehal,
Not quite correct. EJB 3.0 still supports entity beans, they are not removed and not even officially "deprecated". But you're right to some extent - JPA is now the preferred and recommended persistence technology for Java EE (and also Java SE).
BTW: No JEE - it's Java EE
Cheers,
Vladimir -
How to use same transaction when calling CMP entity beans and DAO (JDBC)
We are currently using Weblogic 8.1 SP2 with an Oracle 10g database (using XA thin and non-XA drivers).
We have a session bean that invokes an entity bean and a DAO (data access object pattern) in order to add data in 2 separate tables (account and history). Rows are added to the first (account) table using a CMP Entity bean while inserts are done in the 2nd (history) table using a DAO. Here is some pseudo code:
addHistorySessionBean (trans-attribute="Required")
begin
Step #1 - call addAccountEntityBean (trans- attribute="Required")
Step #2 - call addHistoryDAO (get datasource, connection)
end
The 2nd table (history) has a foreign key constraint to ensure that the corresponding key exists in the first (account) table. Unfortunately, DAO inserts on the 2nd (history) table fail with a foreign key constraint violation (INTEGRITY CONSTRAINT VIOLATION - PARENT KEY NOT FOUND!) since they cannot see the row added to the 1st (account) table in step #1 by the CMP entity bean.
How does one ensure that all this is done in a single transaction ? It appears that the app server creates two seperate transactions (one for the session bean facade and the entity bean and a 2nd transaction (when we retrieve a connection using the same data source JNDI name) for the DAO.
A post on server side suggested using a "<resource-ref>" in the session bean to tie the two potentially separate transactions together, but that does not work for us. However, I am not sure if we are doing that correctly. After we define the resource ref in the session facade bean, do we use the resource ref "name" attribute to lookup the datasource or do we still lookup the datasource by JNDI name ? Do we need to define the resource-ref tag in the entity bean also ?
Does Weblogic allow using a single transaction for this type of a scenario ? How does one specify within Weblogic that the same transaction should be utilized by the entity bean and any subsequent DAOs?
People have also suggested that we defer constraint checking until the transaction(s) are committed but that sounds like a work acount without addressing this issue. Would postponing the constraint checking in Oracle cause any additional overhead ?
Any suggestions with specific examples or documentation on how to address this issue will be gratefully appreciated.Thanks for your suggestion. Unfortunately, this does not work since it appears that there are 2 separate transactions going on here. One, the original one initiated by the session bean and used by the entity bean and the other initiated by the DAO. Any other ideas appreciated.
Hi,
Try setting the delay-database-inserts tag to
ejbCreate in RDBMS descriptor file.
http://bernal/stage/wls/docs81/ejb/DDreference-cmp-jar
.html#1113981
vasanthi ramesh -
Use same transaction in entity-bean and Datasource
Hello
I've got following problem. In my stateless container managed transaction Sessionbean i do some inserts and update on my container managed entity bean. In the same transaction I have to read some informations on the database. Some of those informations are already set by the entity bean, but not yet commited. Now I want to read them through a javax.sql.DataSource. But this Datasource doesn't use the same transaction as the session bean.
Question: Is it possible to let a Datasoucre use the same Transaction as Sessionbean?
(i work with WSAD 4.0.3)
ThanksHi,
You would have to check that you are using an XADataSource instance, instead of a 'regular' DataSource instance (which will not adopt the transaction started by the application server). In particular, the JNDI lookup name of the DataSource should actually point to an instance of XADataSource; a special type for container transactions.
The administration/deployment tools of the WS will allow you to do that, under Resource Factories or DataSources somewhere.
Both types look the same towards your application code, so your session bean is probably fine the way it is and does not need rewriting. It is merely in the setup of the WS server that the difference lies.
Best,
Guy
http://www.atomikos.com -
NON-transactional session bean access entity bean
We are currently profiling our product using Borland OptmizeIt tool, and we
found some interesting issues. Due to our design, we have many session beans which
are non transactional, and these session beans will access entity beans to do
the reading operations, such as getWeight, getRate, since it's read only, there
is no need to do transaction commit stuff which really takes time, this could
be seen through the profile. I know weblogic support readonly entity bean, but
it seems that it only has benefit on ejbLoad call, my test program shows that
weblogic still creates local transaction even I specified it as transaction not
supported, and Transaction.commit() will always be called in postInvoke(), from
the profile, we got that for a single method call, such as getRate(), 80% time
spent on postInvoke(), any suggestion on this? BTW, most of our entity beans are
using Exclusive lock, that's the reason that we use non-transactional session
bean to avoid dead lock problem.
ThanksSlava,
Thanks for the link, actually I read it before, and following is what I extracted
it from the doc:
<weblogic-doc>
Do not set db-is-shared to "false" if you set the entity bean's concurrency
strategy to the "Database" option. If you do, WebLogic Server will ignore the
db-is-shared setting.
</weblogic-doc>
Thanks
"Slava Imeshev" <[email protected]> wrote:
Hi Jinsong,
You may want to read this to get more detailed explanation
on db-is-shared (cache-between-transactions for 7.0):
http://e-docs.bea.com/wls/docs61/ejb/EJB_environment.html#1127563
Let me know if you have any questions.
Regards,
Slava Imeshev
"Jinsong HU" <[email protected]> wrote in message
news:[email protected]...
Thanks.
But it's still not clear to me in db-is-shared setting, if I specifiedentity
lock as database lock, I assumed db-is-shared is useless, because foreach
new
transaction, entity bean will reload data anyway. Correct me if I amwrong.
Jinsong
"Slava Imeshev" <[email protected]> wrote:
Jinsong,
See my answers inline.
"Jinsong Hu" <[email protected]> wrote in message
news:[email protected]...
Hi Slava,
Thanks for your reply, actually, I agree with you, we need to
review
our db
schema and seperate business logic to avoid db lock. I can not say,guys,
we need
to change this and that, since it's a big application and developedsince
EJB1.0
spec, I think they are afraid to do such a big change.Total rewrite is the worst thing that can happen to an app. The
better aproach would be identifying the most critical piece and
make a surgery on it.
Following are questions in my mind:
(1) I think there should be many companies using weblogic serverto
develop
large enterprise applications, I am just wondering what's the maintransaction/lock
mechanism that is used? Transional session / database lock,
db-is-shared
entity
I can't say for the whole community, as for my experience the standard
usage patthern is session fasades calling Entity EJBs while having
Required TX attribute plus plain transacted JDBC calls for bulk
reads or inserts.
is the dominant one? It seems that if you speficy database lock,
the
db-is-shared
should be true, right?Basically it's not true. One will need db-is-shared only if thereare
changes
to the database done from outside of the app server.
(2) For RO bean, if I specify read-idle-timeout to 0, it shouldonly
load
once at the first use time, right?I assume read-timeout-seconds was meant. That's right, but if
an application constantly reads new RO data, RO beans will be
constantly dropped from cache and new ones will be loaded.
You may want to looks at server console to see if there's a lot
of passivation for RO beans.
(3) For clustering part, have anyone use it in real enterpriseapplication?
My concern, since database lock is the only way to choose, how aboutthe
affect
of ejbLoad to performance, since most transactions are short live,if high
volume
transactions are in processing, I am just scared to death about
the
ejbLoad overhead.
ejbLoad is a part of bean's lifecycle, how would you be scared ofit?
If ejbLoads take too much time, it could be a good idea to profile
used SQLs. Right index optimization can make huge difference.
Also you may want cosider using CMP beans to let weblogic
take care about load optimization.
(4) If using Optimization lock, all the ejbStore need to do
version
check
or timestamp check, right? How about this overhead?As for optimistic concurrency, it performs quite well as you can
use lighter isolation levels.
HTH,
Slava Imeshev
"Jinsong Hu" <[email protected]> wrote in message
news:[email protected]...
We are using Exclusive Lock for entity bean, because of we do
not
want
to
load
data in each new transaction. If we use Database lock, that means
we
dedicate
data access calls to database, if database deadlock happens,
it's
hard
to
detect,
while using Exclusive lock, we could detect this dead lock in
container
level.
The problem is, using Exclusive concurrency mode you serialize
access to data represented by the bean. This aproach has negative
effect on ablity of application to process concurrent requests.As
a
result the app may have performance problems under load.
Actually, at the beginnning, we did use database lock and usingtransactional
The fact that you had database deadlocking issues tells that
application logic / database schema may need some review.
Normally to avoid deadlocking it's good to group database
operations mixing in updattes and inserts into one place so
that db locking sequence is not spreaded in time. Moving to
forced serialized data access just hides design/implementation
problems.
session bean, but the database dead lock and frequent ejbLoad
really
kill
us,
so we decided to move to use Exclusive lock and to avoid dead
lock,
we
change
some session bean to non-transactional.Making session beans non-transactions makes container
creating short-living transactions for each call to entity bean
methods. It's a costly process and it puts additional load to
both container and database.
We could use ReadOnly lock for some entity beans, but since weblogicserver will
always create local transaction for entity bean, and we found
transaction
commit
is expensive, I am arguing why do we need create container leveltransaction for
read only bean.First, read-only beans still need to load data. Also, you may seeRO
beans
contanly loading data if db-is-shared set to true. Other reason
can
be
that
RO semantics is not applicable the data presented by RO bean (forinstance,
you have a reporting engine that constantly produces "RO" data,
while
application-consumer of that data retrieves only new data and neverasks
for "old" data). RO beans are good when there is a relatively stable
data
accessed repeatedly for read only access.
You may want to tell us more about your app, we may be of help.
Regards,
Slava Imeshev
I will post the performance data, let's see how costful
transaction.commit
is.
"Cameron Purdy" <[email protected]> wrote:
We are currently profiling our product using Borland
OptmizeIt
tool,
and we
found some interesting issues. Due to our design, we have
many
session
beans which
are non transactional, and these session beans will access
entity
beans
to
do
the reading operations, such as getWeight, getRate, since
it's
read
only,
there
is no need to do transaction commit stuff which really takes
time,
this
could
be seen through the profile. I know weblogic support readonly
entity
bean,
but
it seems that it only has benefit on ejbLoad call, my test
program
shows
that
weblogic still creates local transaction even I specified
it
as
transaction not
supported, and Transaction.commit() will always be called
in
postInvoke(),
from
the profile, we got that for a single method call, such as
getRate(),
80%
time
spent on postInvoke(), any suggestion on this? BTW, most of
our
entity
beans are
using Exclusive lock, that's the reason that we use
non-transactional
session
bean to avoid dead lock problem.I am worried that you have made some decisions based on an improper
understand of what WebLogic is doing.
First, you say "non transactional", but from your description
you
should
have those marked as tx REQUIRED to avoid multiple transactions
(since
non-transactional just means that the database operation becomesits
own
little transaction).
Second, you say you are using exclusive lock, which you shouldonly
use
if
you are absolutely sure that you need it, (and note that it
does
not
work in
a cluster).
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com/coherence.jsp
Tangosol Coherence: Clustered Replicated Cache for Weblogic
"Jinsong Hu" <[email protected]> wrote in message
news:[email protected]...
> -
Entity beans caching non-persistent data between transactions
Some of the properties in our entity bean implementation classes are not declared
in our descriptor files, and therefore, are non-persistent (we are using container-managed
persistence); I will refer to these properties as "non-persistent properties".
In WebLogic 5.1, we've noticed that the non-persistent properties are cached in
between transactions. For instance, I ask for a particular Person (Person(James)),
and I set one of the non-persistent properties (Property(X)) inside Transaction(A).
In Transaction(B) (which is exclusive of Transaction(A)), I access Property(X)
and find that it is the same value as I had set in Transaction(A)- this gives
the appearance that non-persistent entity properties are being cached in between
transactions.
The same appears to hold true in WebLogic 7 SP1, however, we must use the "Exclusive"
concurrency-strategy to maintain this consistency.
I am worried that this assumption we are making of non-persistent properties is
not valid in all cases, and the documentation does not promise anything in the
way of such an assumption. I am worried that the container could kill the Person(James)
entity implementation instance in the pool after Transaction(A), and create a
new Person(James) instance to serve Transaction(B)- once that happens our assumption
fails.
"Database" concurrency strategy seems to fail our assumption on a regular basis,
but that makes sense, since the documentation states that the "database will maintain
the cache", and the container seems more willing to kill instances when they are
finished with, or create new instances for new transactions.
So my question is this: What is exactly guaranteed by the "Exclusive" concurrency-strategy?
Will the assumption that we've made above ever fail under this strategy?
Thanks in advance for any help.
Regards,
JamesIt simply means that there is only one entity bean instance per PK in the
server, and transaction which uses it locks it exclusively.
James DeFelice <[email protected]> wrote:
Thank you for the suggestion. I have considered taking this path, but before I
make a final decision, I was hoping to get a clear answer to the question that
I stated below:
What EXACTLY is guaranteed by the "Exclusive" concurrency-strategy? Maybe someone
from BEA knows?
"Cameron Purdy" <[email protected]> wrote:
To be safe: You should clear those values before the ejb load or set
them
after (or both).
Peace,
Cameron Purdy
Tangosol, Inc.
http://www.tangosol.com/coherence.jsp
Tangosol Coherence: Clustered Replicated Cache for Weblogic
"James DeFelice" <[email protected]> wrote in message
news:[email protected]...
Some of the properties in our entity bean implementation classes arenot
declared
in our descriptor files, and therefore, are non-persistent (we areusing
container-managed
persistence); I will refer to these properties as "non-persistentproperties".
In WebLogic 5.1, we've noticed that the non-persistent properties arecached in
between transactions. For instance, I ask for a particular Person(Person(James)),
and I set one of the non-persistent properties (Property(X)) insideTransaction(A).
In Transaction(B) (which is exclusive of Transaction(A)), I accessProperty(X)
and find that it is the same value as I had set in Transaction(A)-this
gives
the appearance that non-persistent entity properties are being cachedin
between
transactions.
The same appears to hold true in WebLogic 7 SP1, however, we must usethe
"Exclusive"
concurrency-strategy to maintain this consistency.
I am worried that this assumption we are making of non-persistentproperties is
not valid in all cases, and the documentation does not promise anythingin
the
way of such an assumption. I am worried that the container could killthe
Person(James)
entity implementation instance in the pool after Transaction(A), andcreate a
new Person(James) instance to serve Transaction(B)- once that happensour
assumption
fails.
"Database" concurrency strategy seems to fail our assumption on a regularbasis,
but that makes sense, since the documentation states that the "databasewill maintain
the cache", and the container seems more willing to kill instanceswhen
they are
finished with, or create new instances for new transactions.
So my question is this: What is exactly guaranteed by the "Exclusive"concurrency-strategy?
Will the assumption that we've made above ever fail under this strategy?
Thanks in advance for any help.
Regards,
James
Dimitri -
Hello everyone,
So I'm going to blurt out two classes of code. First is a plain entity bean and the second is a helper class with two static methods to help me to convert Object into byte[] and vice versa without much worrying.
Now the problem is, how to persist this entity bean and it's two Objects (two Lists) in a more "J2EE5 way". I just need to store these two Objects, or any Serializable Object, into persistent storage. So how to avoid this serialization by-hand that I'm doing... ?
Thank you for your interest - and help :),
Samuli
Maybe using a @Lob notation or such? I've tried, but I can't get it workign. @Lob itself is not enough since it results in casting problems when retrieveing the data back from the persistent storage.
And oh, I'm just using the simple CMP with this.. EJB using EntityManager's persist method to store and so on..
EntityBean class (imports and packages excluded)
@Entity
public class MessageHandlerChain implements java.io.Serializable {
@TableGenerator(
name="messageHandlerChainIDGenerator",
allocationSize=1,
initialValue=1
@GeneratedValue(
generator="messageHandlerChainIDGenerator",
strategy=GenerationType.TABLE
@Id
private Integer messageHandlerChainID;
@Lob
private byte[] messageHandlers;
@Lob
private byte[] messageHandlerProperties;
@Transient
private List<String> messageHandlersObj = new ArrayList<String>();
@Transient
private List<Map<String,String>> messageHandlerPropertiesObj = new ArrayList<Map<String,String>>();
* Constructs an empty instance of <code>MessageHandlerChain</code> without any properties.
public MessageHandlerChain() {
public Integer getMessageHandlerChainID() {
return messageHandlerChainID;
public void setMessageHandlerChainID(Integer messageHandlerChainID) {
this.messageHandlerChainID = messageHandlerChainID;
public List<String> getMessageHandlers() {
return messageHandlersObj;
public void setMessageHandlers(List<String> messageHandlersObj) {
if (messageHandlersObj == null) {
System.out.println("[MessageHandlerChain] setMessageHandlers() can't be given a null value.");
return;
this.messageHandlersObj = messageHandlersObj;
public List<Map<String,String>> getMessageHandlerProperties() {
return messageHandlerPropertiesObj;
public void setMessageHandlerProperties(List<Map<String,String>> messageHandlerPropertiesObj) {
if (messageHandlerPropertiesObj == null) {
System.out.println("[MessageHandlerChain] setMessageHandlerProperties() can't be given a null value.");
return;
this.messageHandlerPropertiesObj = messageHandlerPropertiesObj;
@PrePersist
* This method is invoked by the persistence provider prior to every persist operation.
* This is needed because we need to convert, serialize, our <code>@Transient</code> annotated objects into <code>byte[]</code> streams
* so that they can be written into the database.
public void prePersist() {
System.out.println("[MessageHandlerChain] prePersist()");
if (messageHandlerPropertiesObj != null)
messageHandlerProperties = BlobConverter.objectToBytes(messageHandlerPropertiesObj);
if (messageHandlersObj != null)
messageHandlers = BlobConverter.objectToBytes(messageHandlersObj);
@PostLoad
* This method is invoked by the persistence provider after every load operation.
* This is needed because we need to convert, deserialize, <code>byte[]</code> streams back to our <code>@Transient</code> annotated objects.
public void postLoad() {
System.out.println("[MessageHandlerChain] postLoad()");
try {
if (messageHandlerProperties != null)
messageHandlerPropertiesObj = (List<Map<String,String>>)BlobConverter.bytesToObject(messageHandlerProperties);
if (messageHandlers != null)
messageHandlersObj = (List<String>)BlobConverter.bytesToObject(messageHandlers);
} catch (ClassCastException e) {
System.out.println("[MessageHandlerChain] postLoad() Class Cast Exception: "+e);
public String toString() {
return "[MessageHandlerChain] messageHandlerChainID="+getMessageHandlerChainID()+", messageHandlers="+getMessageHandlers()+", messageHandlerProperties="+getMessageHandlerProperties();
The helper class
* <code>BlobConverter</code> is a simple helper class to encode and decode classes as byte[] so that they can be stored into persistent storage.
* @author Samuli Piela
public class BlobConverter {
public static byte[] objectToBytes(Object o) {
ByteArrayOutputStream baos = new ByteArrayOutputStream(512);
ObjectOutputStream oos = null;
try {
oos = new ObjectOutputStream(baos);
oos.writeObject(o);
return baos.toByteArray();
} catch (InvalidClassException e) {
System.out.println("objectToBytes("+o+"): Invalid Class: "+e);
} catch (NotSerializableException e) {
System.out.println("objectToByte("+o+"): Object not serializable: "+e);
} catch (Exception e) {
System.out.println("objectToBytes("+o+"): Exception: "+e);
} finally {
if (oos != null) {
try {
oos.close();
} catch (IOException e) {
System.out.println("objectToBytes(): Stream could not be closed: "+e);
if (baos != null) {
try {
baos.close();
} catch (IOException e) {
System.out.println("objectToBytes(): Stream could not be closed: "+e);
oos = null;
baos = null;
return null;
public static Object bytesToObject(byte[] byteArray) {
ByteArrayInputStream bais = new ByteArrayInputStream(byteArray);
ObjectInputStream ois = null;
try {
ois = new ObjectInputStream(bais);
Object o = ois.readObject();
return o;
} catch (ClassNotFoundException e) {
System.out.println("bytesToObject(): Class not found: "+e);
} catch (InvalidClassException e) {
System.out.println("bytesToObject(): Invalid Class: "+e);
} catch (IOException e) {
System.out.println("bytesToObject(): IOException: "+e);
} catch (Exception e) {
System.out.println("bytesToObject(): Exception: "+e);
} finally {
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
System.out.println("bytesToObject(): Stream could not be closed: "+e);
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
System.out.println("bytesToObject(): Stream could not be closed: "+e);
ois = null;
bais = null;
return null;
}anyone?
-
Entity Bean can only use container-managed transaction demarcation?
In <<Designing Enterprise Application with J2EE 2nd>>
Section 2.3.3.3 Enterprise Bean Transactions,it says:Entity beans can only use container-managed transaction demarcation.
That means,i can not get UserTransaction from EJBContext.
Is that true?Yes this is the requirement of the specs. Your ejb code generator should give you the error if you use usertransaction.
--Ashwani -
How can I control the EJB's Transaction with entity bean
If I use entity bean, the Transaction is managed by container.and I want to create JDBC Connection by myselft ,not the Datasource,how is the transaction is controlled by the container,if transaction is not controlled ,how can I control it??
Hi,
If you want to control the transaction your self then you need to use javax.transaction.UserTransaction interface and methods defined by it.
Hope this helps
Vishal -
Question about multiple RequiresNew in Entity Bean transaction
Hi I've got a problem concerning transactions:
In both cases I've got a CMP Entity Bean called "Account" with some mothods like
increaseBalance(double amount)
decreaseBalance(double amount)
transferMoney(double amount)
for all methods the TransactionAttribute is "RequiresNew". When calling first decreaseBalance(amount) and afterwords
increaseBalance(amount), bothfrom within transferMoney(amount). When setting entityContext.RollbackOnly()
I would expect this rollback doesn't undo my changes because they are in a different transaction, which has been comitted
when the methods finished, but both are rolled back.
I thought there are no "nested transactions" in J2EE. Isn't this one?
Thanks!
MartinAhhhh! Right! If I call "this.increase(balance)" from the AccountBean method "transferMoney", the container has no chance to create a new transaction, so the same transaction as in "transferMoney" is used. I didn't think about that, but of course...
So one should never call a bean method directly even when it is a method of the same instance the thread is currently in.
Thanks a lot!
Maybe you are looking for
-
Installing on macbook pro.
hi, im a student who is trying to install photoshop cs5 extended onto my macbook pro. i have completed an online form and attached a scanned student id card with it, but i am not sure what to do now. i have not put the disk in as the instructions say
-
How to do Post Install SAP Cryptographic in Netweaver CE 7.1 to enable SSL?
Dear all, I have install sap netweaver CE7.1 and SSM 7.5. During installation netweaver CE7.1, i didn't tick install SAP Crytographic Library, and after that NWCE setup, now i want to install Crytographic file that i have download. here picture durin
-
Store button in Music app doesn't work on Verizon iPhone 4 w/iOS 5?
On my Verizon iPhone 4 with iOS 5.0.1, in the Music app, tapping the Store button does nothing. Also, there are several screens with links to the iTunes store. If I tap one of these links, I get this message (this time, from the Podcasts screen): Res
-
R/3 table data for BI reporting ?
In R/3 i have a table and I want to take the complete table data into SAP BI system for reporting . In how many ways can I take the data to sap BI system. In how many ways I can make use of that table for reporting in BI please suggest me some .
-
i dont know why but my macbook pro just stop to open a web page and frezee there im very nervios obut somthing that can be...... help me please. it is brand new like 10 days