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

江湖上 发布于 2016/05/02 19:13
阅读 272
收藏 0

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



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

加载中
0
FL_NC
FL_NC
hibernate.cfg.xml 少了<mapping resource="xx/xxx/......./Book.hbm.xml"/>xxx是对应包的路径
江湖上
江湖上
@FL_NC 好的,我再检查一下,谢谢你...
FL_NC
FL_NC
回复 @江湖上 : 你的文件确实是少了这个,可能还是有其他问题,包要隔开,比如在 com.hsp.sina 要写成 com/hsp/sina
江湖上
江湖上
谢谢回答,试了,依然不行啊...
返回顶部
顶部