what is the most special annotation for handling transactions in spring service layer?
@Transactional
And how should it be used when declaring read only and writing transactions?
@Service("businessUnitListService")
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class BusinessUnitListServiceImpl implements BusinessUnitListService {
@Override
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public List getAllBusinessUnitList(Long businessUnitId) {
return businessUnitListDAO.getAllBusinessUnitList(businessUnitId);
}
@Override
@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
public void deleteBusinessUnitList(String data) {
if (data.indexOf('[') > -1) {
List deleteBusinessUnitList = businessUnitListUtil.getListIdFromJSON(data);
for (Long id : deleteBusinessUnitList) {
businessUnitListDAO.deleteBusinessUnitList(id);
}
} else {
Long id = Long.parseLong(data.toString());
businessUnitListDAO.deleteBusinessUnitList(id);
}
}
}
if you missed out one of above annotation properly..
you will see only following sql statements on hibernate console
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')
but data will not be inserted when it is a insert query..
if it was configured correctly.
you will see
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into transaction.BUSINESS_UNIT_LIST (BUSINESS_UNIT_ID, CODE, DESCRIPTION, VERSION_ID, BUSINESS_UNIT_LIST_ID) values (?, ?, ?, ?, ?)
And how should it be used when declaring read only and writing transactions?
@Service("businessUnitListService")
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public class BusinessUnitListServiceImpl implements BusinessUnitListService {
@Override
@Transactional(propagation=Propagation.SUPPORTS,readOnly=true)
public List
return businessUnitListDAO.getAllBusinessUnitList(businessUnitId);
}
@Override
@Transactional(propagation=Propagation.REQUIRED,readOnly=false)
public void deleteBusinessUnitList(String data) {
if (data.indexOf('[') > -1) {
List
for (Long id : deleteBusinessUnitList) {
businessUnitListDAO.deleteBusinessUnitList(id);
}
} else {
Long id = Long.parseLong(data.toString());
businessUnitListDAO.deleteBusinessUnitList(id);
}
}
}
if you missed out one of above annotation properly..
you will see only following sql statements on hibernate console
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')
but data will not be inserted when it is a insert query..
if it was configured correctly.
you will see
Hibernate: select businessun0_.BUSINESS_UNIT_ID as col_0_0_, businessun0_.CODE as col_1_0_, businessun0_.DESCRIPTION as col_2_0_ from transaction.BUSINESS_UNIT businessun0_
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into transaction.BUSINESS_UNIT_LIST (BUSINESS_UNIT_ID, CODE, DESCRIPTION, VERSION_ID, BUSINESS_UNIT_LIST_ID) values (?, ?, ?, ?, ?)
Comments
Post a Comment