开发者社区> 问答> 正文

Hibernate生成映射文件失败????报错

最近在自己琢磨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.NullPointerException
P.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>



麻烦各位帮忙看看,问题出在哪里了,我折腾了一下午,依然没能解决问题,谢谢...

展开
收起
爱吃鱼的程序员 2020-06-09 14:57:41 623 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    <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谢谢回答,试了,依然不行啊...

    2020-06-09 14:57:59
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载