JAXB,MOXy,JSR-303,JPA - 在解组后禁用JSR-303验证?

时间:2014-10-22 19:16:33

标签: jaxb bean-validation moxy

我通过外部服务收到一条XML消息,我可以使用MOXy作为我的JAXB提供程序解组到POJO中。我目前能够使用JPA(Hibernate)将对象持久化到数据库中,并且当遇到无效数据时,JSR-303验证按预期工作。

我的挑战是,在持久性之前,我想向POJO添加两个字段 - 提交者的用户ID和接收记录的日期。添加属性工作正常,一切都按预期持续。但是,只要我将@NotNull约束添加到另外两个字段(以保护从其他进程写入同一个表),unmarshal就会失败,并出现以下错误:

对于未编组的bean违反了约束:

有没有办法在解组后禁用JSR-303检查?我有很多这些我将不得不在不久的将来创建并且每个传入消息有2个不同的对象需要保持不会是最佳的。

此外 - 还有其他非审计相关信息必须在以后注入,因此添加不同的审计解决方案将无济于事。

提前感谢所有帮助!

1 个答案:

答案 0 :(得分:1)

要在MOXy中关闭BV:

    <!DOCTYPE html>
<html lang="en">
<head>
    <title>TITLE!</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="mystyle.css" />
</head>
<body>
    <input class="burger-check" id="burger-check" type="checkbox"><label for="burger-check" class="burger"></label>
    <link rel="stylesheet" type="text/css" href="mystyle.css"/>
    <nav id="navigation1" class="navigation">
    <ul>
        <li><a href="#">Home</a> <span class="glyphicon glyphicon-home" aria-hidden="true"></span></li> 
        <li><a href="#contact" data-toggle="modal">Contact Me</a> <span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></li>
        <li><a href="#">About Me</a> <span class="glyphicon glyphicon-user" aria-hidden="true"></span></li>
    </ul>

    </nav>

    <div class="page-header">
        <h1>Example page header</h1>  <!--Practical name and number  -->
    </div>
        <div class="table-responsive" id="main_table">
            <table class="table table-hover">
            <thead>
              <tr>
                <th class="text-center">No.</th>
                <th class="text-center">Name</th>
                <th class="text-center">Download</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td class="text-center">1</td>
                <td class="text-center">xxxx</td>
                <td class="text-center"><a href="download/1.jpg" download="TT.png"><button type="button" class="btn btn-success">DOWNLOAD</button></a></td>
              </tr>
              <tr>
                <td class="text-center">2</td>
                <td class="text-center">yyyy</td>
                <td class="text-center"><a href="download/2.jpg" download="TT.png"><button type="button" class="btn btn-success">DOWNLOAD</button></a></td>
              </tr>
              <tr>
                <td class="text-center">3</td>
                <td class="text-center">zzzzz</td>
                <td class="text-center"><a href="download/3.jpg" download="TT.png"><button type="button" class="btn btn-success">DOWNLOAD</button></a></td>
              </tr>
            </tbody>
          </table>
      </div>
    <!-- modal starts here -->

    <div class="modal fade" id="contact" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <form class="form-horizontal" method="post" action="send.php">  
                    <div class="modal-header">
                        <h1>Contact Me </h1>
                    </div>
                    <div class="modal-body">
                        <div class="form-group">
                            <label for="contact-name" class="col-sm-2 control-label">Name:</label>
                            <div class="col-sm-10">
                              <input type="text" name="name" class="form-control" id="contact-name" placeholder="Full name">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="contact-email" class="col-sm-2 control-label">Email:</label>
                            <div class="col-sm-10">
                              <input type="email" name="email" class="form-control" id="contact-email" placeholder="you@example.com">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="contact-msg" class="col-sm-2 control-label">Message:</label>
                            <div class="col-sm-10">
                              <textarea name="msg" class="form-control" rows="8"></textarea>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <a href="https://www.facebook.com/shubhamdeshmukh193" target="_blank"><img class="pull-left" src="images/fb.png" alt="Contact on Facebook" style="width:30px;height:30px;"></a>
                      <a type="button" class="btn btn-default" data-dismiss="modal">Close</a>
                      <button class="btn btn-primary" type="submit">Send</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

    <!-- till here -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>

https://wiki.eclipse.org/EclipseLink/Examples/MOXy/BVinJAXB/GettingStarted