Fórumok
Transaction management?
Dhanwan S Ramasane, módosítva 9 év-val korábban
Transaction management?
Junior Member Bejegyzések: 27 Csatlakozás dátuma: 2012.04.09. Legújabb bejegyzések
Hello All,
I am creating User and blogs entry.
Here I want to maintain transaction on User creation and Blogs Entry creation combinedly. Like there should be commit on success of both or roll back on failure.
Currently the transaction is on User creation and Blogs Entry creation separately so how i can make it combinedly?
Thanks !!
I am creating User and blogs entry.
Here I want to maintain transaction on User creation and Blogs Entry creation combinedly. Like there should be commit on success of both or roll back on failure.
Currently the transaction is on User creation and Blogs Entry creation separately so how i can make it combinedly?
Thanks !!
Dhanwan S Ramasane, módosítva 9 év-val korábban
RE: Transaction management?
Junior Member Bejegyzések: 27 Csatlakozás dátuma: 2012.04.09. Legújabb bejegyzésekDhanwan S Ramasane:
Hello All,
I am creating User and blogs entry.
Here I want to maintain transaction on User creation and Blogs Entry creation combinedly. Like there should be commit on success of both or roll back on failure.
Currently the transaction is on User creation and Blogs Entry creation separately so how i can make it combinedly?
Thanks !!
Hello,
How can i do this? should i create new service or what any idea?
Thanks !!
Achraf BEN AISSI, módosítva 9 év-val korábban
RE: Transaction management?
New Member Bejegyzések: 14 Csatlakozás dátuma: 2010.12.30. Legújabb bejegyzések
Hello,
did you try this?
Or this (it's not very beautiful) ?
did you try this?
#
# Set this to true to disable database transaction management during
# verifies. This forces autocommit which will speed up the verify process.
#
verify.database.transactions.disabled=true
Or this (it's not very beautiful) ?
Connection connection = null;
PreparedStatement ps = null;
try{
connection = getConnection();
connection.setAutoCommit(false);
ps = dbConnection.prepareStatement("insert into ... values (?, ?, ?, ?)");
[....]
ps.executeUpdate();
finally {
if (ps != null) {
ps.close();
}
if ( connection != null) {
connection.close();
}
}
Dhanwan S Ramasane, módosítva 9 év-val korábban
RE: Transaction management?
Junior Member Bejegyzések: 27 Csatlakozás dátuma: 2012.04.09. Legújabb bejegyzések
Hi Achraf BEN AISSI,
Thanks for your reply !!
But this is related to table verification process, even its default value is true.
My question is while adding user we uses UserLocalServiceUtil.addUser... method so any exception happened inside this it will automatically handle rollback and all that related to transaction, same thing with adding blogs entry. Suppose i written one method addUserAndBlogsEntry. From this mehtod i am calling user creation and blogs entry creation method. While execution user added successfully but blogs entry failed then added user should be roll back. So pls tell me the right way how i can achieve this in liferay.(For this i can write one new entity, then service builder creates services, in serviceimpl i can write this method so transaction will handle automatically. But thing is i don't want to create new entity... so pls tell me any other way to do this.)
Thanks !!
Thanks for your reply !!
But this is related to table verification process, even its default value is true.
My question is while adding user we uses UserLocalServiceUtil.addUser... method so any exception happened inside this it will automatically handle rollback and all that related to transaction, same thing with adding blogs entry. Suppose i written one method addUserAndBlogsEntry. From this mehtod i am calling user creation and blogs entry creation method. While execution user added successfully but blogs entry failed then added user should be roll back. So pls tell me the right way how i can achieve this in liferay.(For this i can write one new entity, then service builder creates services, in serviceimpl i can write this method so transaction will handle automatically. But thing is i don't want to create new entity... so pls tell me any other way to do this.)
Thanks !!
Ravi Kumar Gupta, módosítva 9 év-val korábban
RE: Transaction management?
Liferay Legend Bejegyzések: 1302 Csatlakozás dátuma: 2009.06.24. Legújabb bejegyzések
User user = null;
try{
// create user
user = UserLocalServiceUtil.createxxx();
if(user!=null){
try{
// create blog here
}catch(Exception e){
// exception that blog creation failed..
// delete user here-- use the method responsible for deleting user
}
}
}
}catch(Exception e){
}
See if this works for you..
try{
// create user
user = UserLocalServiceUtil.createxxx();
if(user!=null){
try{
// create blog here
}catch(Exception e){
// exception that blog creation failed..
// delete user here-- use the method responsible for deleting user
}
}
}
}catch(Exception e){
}
See if this works for you..
Dhanwan S Ramasane, módosítva 9 év-val korábban
RE: Transaction management?
Junior Member Bejegyzések: 27 Csatlakozás dátuma: 2012.04.09. Legújabb bejegyzések
Thanks Ravi for your quick reply !!
In your code, the problem handling is done by us only, but overall good solution thanks again!!
In your code, the problem handling is done by us only, but overall good solution thanks again!!
Achraf BEN AISSI, módosítva 9 év-val korábban
RE: Transaction management?
New Member Bejegyzések: 14 Csatlakozás dátuma: 2010.12.30. Legújabb bejegyzések
Did you read this Blog ?:
http://www.liferayaddicts.net/blogs/-/blogs/transaction-management-with-liferay-service
http://www.liferayaddicts.net/blogs/-/blogs/transaction-management-with-liferay-service
Ravi Kumar Gupta, módosítva 9 év-val korábban
RE: Transaction management?
Liferay Legend Bejegyzések: 1302 Csatlakozás dátuma: 2009.06.24. Legújabb bejegyzések
Are you creating user and blog via script? Your custom portlet?