---
title: "JPA会自动在classpath路径下寻找*.hbm.xml文件"
author: "stephansun"
date: "2012-04-02T12:15:59Z"
tags: []
categories: ["编程语言"]
slug: "jpa-classpath-hbm-xml"
draft: false
lastmod: "2012-04-02T12:15:59Z"
id: 1402874
url: "https://stephansun.iteye.com/blog/1402874"
---

刚才在看Hibernate 4.1.0.Final的[Getting Started Guide](http://docs.jboss.org/hibernate/orm/4.1/quickstart/en-US/html_single/ "Hibernate Getting Started Guide")的时候，测试JPA代码时发现报错，原因是我将文档中的3个模块，hbm、annotation、jpa合在一个工程里，导致有一个Event.hbm.xml和JPA对应的Event.java这个实体（Entity）混合在一起了，hbm中的主键对应列名为event\_id，JPA中的主键对应列名为id，生成出来的建表语句既有event\_id列又有id列，仅将id列作为primary key，测试insert代码时，发出的sql语句中没有包含event\_id，导致报错。话说，这JPA启动时还会遍历一遍classpath，感知所有的\*.hbm.xml文件？没怎么研究过JPA，也许是我土了![](/images/smiles/icon_redface.gif)