J2EE进阶(十九)FileNotFoundException: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd

解决J2EE Hibernate异常

#J2EE进阶(十九)Nested exception: java.io.FileNotFoundException: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd
  在调试过程中,莫名奇妙的出现了“Nested exception:java.io.FileNotFoundException: http://hibernate.org/dtd/hibernate-mapping-3.0.dtd”的错误,截图如下:
这里写图片描述
  对于这一错误,查看错误提示可知,是由于“http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20”文件找不到造成的。之前也没有找不到这一文件啊。由于是获取网络文件,怀疑是网络造成的问题,可是网络链接良好。从网上搜寻答案,一番折腾一无所获,回去继续看错误报告,结合错误源文件,发现了下面的异常。
这里写图片描述
  原来是由于不知何时手误将“http://hibernate.org/dtd/hibernate-mapping-3.0.dtd%20”的后面多加了一个空格,导致文件找不到了。我只想说“这也可以?”将空格删除之后,问题得到解决。
  后期经过确认,是由于利用Hibernate的反向工程生成.hbm.xml文件时多加的一个空格,坑!
##附 org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
  分析及解决:
  要操作的数据表中的id(即主键)的类型设置成了“自动增长类型”,而在你的
hibernate.cfg.xml中,id的生成方式是assigned,即

<id name="id" type="integer">
    column name="id" />
    <generator class="assigned" />
</id>

  这种搭配是矛盾的!因为主键的assigned生成方式由程序自动生成表的主键,即在你的测试程序中要调用setId()方法,且必须在调用save()前调用(或者说在调用save()前必须指定id,其实就是说,主键值不能为空!)。
  把主键的生成方式改为native,它的特征是能够根据底层数据库自动选择主键生成方式。

![这里写图片描述](https://img-blog.csdnimg.cn/img_convert/46cc348062c27bf57424afe162b04ab4.png) ![这里写图片描述](https://img-blog.csdnimg.cn/img_convert/f9c024e20306fb0e4e3e84a15aab3217.png)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html lang="zh-CN" class="bootstrap-admin-vertical-centered"> <head> <meta charset="UTF-8"> <title>图书馆管理系统</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <link rel="stylesheet" href="static/css/bootstrap.min.css"> <link rel="stylesheet" href="static/css/bootstrap-theme.min.css"> <link rel="stylesheet" href="static/css/bootstrap-admin-theme.css"> <link rel="stylesheet" href="static/css/bootstrap-admin-theme.css"> <script src="static/js/bootstrap.min.js"></script> <script src="static/jQuery/jquery-3.1.1.min.js"></script> <script src="static/ajax-lib/ajaxutils.js"></script> <script src="static/js/login.js"></script> </head> <style type="text/css"> .alert{ margin: 0 auto 20px; text-align: center; } </style> <script src="static/js/jquery.min.js"></script> <script src="static/js/bootstrap.min.js"></script> <body class="bootstrap-admin-without-padding"> 池州学院 230312242 杨洪博 课设 <div style="background-image: url(&#39;image/2.png&#39;); background-size: cover; background-repeat: no-repeat; background-position: center;"></div> <div class="col-lg-12"> <div class="alert alert-info"> <a class="close" data-dismiss="alert" href="#">×</a> 欢迎登录图书馆管理系统 </div> <form class="bootstrap-admin-login-form" method="post" action="/books/LoginServlet"> <% String state = (String)session.getAttribute("state"); session.removeAttribute("state"); if(state!=null){ %> <label class="control-label" for="username">密码错误</label> <%}%> <div class="form-group"> <label class="control-label" for="username">账 号</label> <input type="text" class="form-control" id="username" name="username" required="required" placeholder="学号"/> <label class="control-label" for="username" style="display:none;"></label> </div> <div class="form-group"> <label class="control-label" for="password">密 码</label> <input type="password" class="form-control" id="password" name="password" required="required" placeholder="密码"/> <label class="control-label" for="username" style="display:none;"></label> </div> <label class="control-label" for="password">没有账号请<a href="/books/register.jsp" style="color:blue;">注册</a></label> <br> <input type="submit" class="btn btn-lg btn-primary" value="登    录"/> </form> </div> </div> </div> <div class="modal fade" id="modal_info" tabindex="-1" role="dialog" aria-labelledby="addModalLabel"> <div class="modal-dialog" role="document"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button> <h4 class="modal-title" id="infoModalLabel">提示</h4> </div> <div class="modal-body"> <div class="row"> <div class="col-lg-12" id="div_info"></div> </div> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" id="btn_info_close" data-dismiss="modal">关闭</button> </div> </div> </div> </div> </body> </html>文件路径没问题 但图片显示不出来
最新发布
06-22
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

No Silver Bullet

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值