2
我正在用Spring roo管理一個項目,並且我在使用hibernate,當我嘗試使用這個控制器方法時,我有這個異常消息:無法初始化代理 - 沒有會話Spring roo無法初始化代理 - 沒有會話
org.hibernate.collection.internal.AbstractPersistentCollection.withTemporarySessionIfNeeded(AbstractPersistentCollection.java:186)
org.hibernate.collection.internal.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:545)
org.hibernate.collection.internal.AbstractPersistentCollection.read(AbstractPersistentCollection.java:124)
org.hibernate.collection.internal.PersistentSet.iterator(PersistentSet.java:180)
com.macrosystem.rentacar.service.DefaultJournalService.getReservationsProfitPerYear(DefaultJournalService.java:142)
com.macrosystem.rentacar.service.DefaultJournalService.getTotalLossAndProfitPerYear(DefaultJournalService.java:159)
com.macrosystem.rentacar.service.DefaultJournalService.getTotalLossAndProfit(DefaultJournalService.java:173)
com.macrosystem.rentacar.web.JournalController.lossAndPorfit(JournalController.java:44)
這裏是控制器方法:
@RequestMapping("/lossandprofit.json")
public @ResponseBody List<Map<String, Number>> lossAndPorfit(){
return journalService.getTotalLossAndProfit() ;
}
和服務方法使所述異常
@Override
@Transactional
public BigDecimal getReservationsProfitPerYear(int year) {
BigDecimal reservationsprofit = new BigDecimal(0) ;
if(vehicle == null){
log.warn("vehicule is null") ;
}
Set<Reservation> reservations = vehicle.getReservations() ;
Iterator<Reservation> iterator = reservations.iterator() ;
while(iterator.hasNext()){
Reservation current = iterator.next() ;
GregorianCalendar calendar = new GregorianCalendar() ;
calendar.setTime(current.getStartDate()) ;
if (calendar.get(Calendar.YEAR) == year){
reservationsprofit = reservationsprofit.add(current.getAmount()) ;
}
}
return reservationsprofit;
}
爲什麼我有一個例外,即使我與標註我@Transactionnal服務方法,我看着applicationContext.xml文件,發現這條線
<tx:annotation-driven mode="aspectj"
transaction-manager="transactionManager" />
難道是取消該效果模式=「切面」部分那個註釋?