最近在自己琢磨Hibernate ORM框架;
开发环境配置:Ubuntu 14.04 LTS + Eclipse 4.5.2 + JBoss Tools 4.3.1.Final;
在生成映射文件时报错,具体信息如下:
hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"> <hibernate-configuration> <session-factory> <!-- 1、数据源配置 --> <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://127.0.0.1:3306/jdbc</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.connection.password">150094</property> <!-- 2、Hibernate基本信息配置 --> <!-- 控制台输出格式化SQL语句. --> <property name="show_sql">true</property> <property name="format_sql">true</property> </session-factory> </hibernate-configuration>
Java类(POJO):
public class Book { // 成员属性; private int id; // 图书id; private String title; // 图书名称; private String author; // 图书作者; private String press; // 出版社; // 构造方法; public Book(){} // Getter and Setter; public int getId() { return id; } public void setId(int id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getAuthor() { return author; } public void setAuthor(String author) { this.author = author; } public String getPress() { return press; } public void setPress(String press) { this.press = press; } // 成员方法; @Override public String toString() { return "Book [id=" + id + ", title=" + title + ", author=" + author + ", " + "press=" + press + "]"; } }
报错信息:
An error has occurred. See error log for more details. java.lang.NullPointerExceptionP.S.项目是使用Maven 3.3.3构建的,pom.xml文件如下:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>cn.edu.hainu</groupId> <artifactId>HibernateLearning</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>HibernateLearning</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <!-- JUnit4 --> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- Hibernate-core 5.1.0 --> <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> <version>5.1.0.Final</version> <scope>compile</scope> </dependency> <!-- JBoss-trancsaction-api --> <dependency> <groupId>org.jboss.spec.javax.transaction</groupId> <artifactId>jboss-transaction-api_1.1_spec</artifactId> <version>1.0.1.Final</version> <scope>compile</scope> </dependency> <!-- MySQL JDBC --> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>5.1.38</version> <scope>runtime</scope> </dependency> </dependencies> </project>
<spanstyle="font-family:'MicrosoftYaHei',Verdana,sans-serif,宋体;font-size:14px;line-height:22px;background-color:#FFFFFF;">hibernate.cfg.xml少了<mappingresource="xx/xxx/......./<spanstyle="font-family:Consolas,'BitstreamVeraSansMono','CourierNew',Courier,monospace;font-size:14px;line-height:15.4px;background-color:#FFFFFF;">Book.hbm.xml"/>xxx是对应包的路径
<atarget='_blank'>@FL_NC好的,我再检查一下,谢谢你...回复<aclass='referer'target='_blank'>@江湖上:你的文件确实是少了这个,可能还是有其他问题,包要隔开,比如在com.hsp.sina要写成com/hsp/sina谢谢回答,试了,依然不行啊...
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。