小编Ole*_*nko的帖子

无法在Spring应用程序中处理@Transactional方法中的hibernate异常

我有个问题.我使用Spring + Hibernate,我无法处理标记为@Transactional的方法中的异常.以前,当我使用Spring JDBC时,一切工作都很好.

DAO类标有@Repository.
这是我旧代码的秘密.
在服务中:

@Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW, rollbackFor = {Exception.class})
        public boolean bookTickets(Integer userId, List<Integer> ticketsId) throws TicketsServiceException {
            Integer currId = null;
            try {
                for (Integer ticketId : ticketsId) {
                    currId = ticketId;
                    Ticket ticket = ticketDAO.getTicketById(ticketId);
                    bookingDAO.bookTicket(ticket, userId);
                }
            } catch (DuplicateKeyException e) {
                throw new TicketsServiceException(String.format(MESSAGE_TICKET_ALREADY_BOOKED, currId));
            } catch (EmptyResultDataAccessException e) {
            throw new TicketsServiceException(String.format(MESSAGE_NO_SUCH_TICKET, currId));
            }
            return true;   
Run Code Online (Sandbox Code Playgroud)


在道:

@Transactional(propagation = Propagation.MANDATORY)
public void bookTicket(Ticket ticket, final int …
Run Code Online (Sandbox Code Playgroud)

spring hibernate transactions exception-handling

7
推荐指数
1
解决办法
5668
查看次数

对象数组的C++问题

我们有一个任务来创建一个二十一点游戏.

贝娄是我的代码的简化版本:

#include <iostream>
#include <string>
#include <time.h>

using namespace std;

class Deck
{
private:
    Card cards[52];    <-- HERE!!
public:

};

class Card
{
private:
    int suit;
    int number;
public:


    int getSuit();
    int getNumber();
    void setCard(int suit, int number);

};
int Card::getSuit()
{
    return suit;
}

int Card::getNumber()
{
    return number;
}

void Card::setCard(int s, int n)
{
    suit = s;
    number = n;
}

class Players
{
private:
    Card PlayersCards[10];
public: 
    /*Card getCard();*/


};

//Card Players::getCard()
//{
//  return; …
Run Code Online (Sandbox Code Playgroud)

c++ arrays object

7
推荐指数
1
解决办法
205
查看次数

Excel VBA性能编码设置

我一直在研究如何在Excel VBA中加速我的代码,我遇到了以下有用的设置.我的问题是:是否可以将以下代码行设置为一个变量,我可以将其设置为On或Off以激活整个列表?就是这样的

speedUpCode = On
Run Code Online (Sandbox Code Playgroud)

将设置以下所有设置,如果设置为Off,则会将以下所有内容反转为True/xlCalculationAutomatic

With Application
    .ScreenUpdating = False
    .DisplayStatusBar = False
    .Calculation = xlCalculationManual
    .EnableEvents = False
End With
ActiveSheet.DisplayPageBreaks = False 'note this is a sheet-level setting
Run Code Online (Sandbox Code Playgroud)

excel vba excel-vba

1
推荐指数
1
解决办法
302
查看次数

创建一个随机数并检查它是奇数还是偶数

我想创建一个批处理文件,当运行时,创建一个从0到100的随机整数,然后通过if语句运行它,检查它是奇数还是偶数.我遇到了一些麻烦,所以这就是我到目前为止的情况.

@echo off
set /a num=%random% %%100 +1
if ( num % 2 == 0 ) {
     //even
}
else
{
    //odd
}
Run Code Online (Sandbox Code Playgroud)

我得到的错误是 - "此时意外数字"

random if-statement batch-file

0
推荐指数
1
解决办法
2432
查看次数