论坛首页 Java企业应用论坛

一个由hbm.xml文件格式不正确引发的悲催

浏览 4170 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2012-02-02  
项目中运用了Hibernate3,报错如下:
 INFO [main] - Mapping class: com.toone.imps.st.managesectioninfo.model.ManageSe
ctionInfo -> IMPS_ST_MANAGESECTIONINFO
ERROR [main] - Error parsing XML: XML InputStream(2) The processing instruction
target matching "[xX][mM][lL]" is not allowed.
ERROR [main] - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'transactionManager' defined in class path resource [config/itop/tor/TORC
onfig.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean
 property 'sessionFactory'; nested exception is org.springframework.beans.factor
y.BeanCreationException: Error creating bean with name 'sessionFactory' defined
in file [F:\projects\zjxm2011\Trunk\zjgl\war\WEB-INF\classes\com\toone\ipms\ipms
-spring-global.xml]: Initialization of bean failed; nested exception is org.hibe
rnate.InvalidMappingException: Could not parse mapping document from input strea
m
org.springframework.beans.factory.BeanCreationException: Error creating bean wit
h name 'sessionFactory' defined in file [F:\projects\zjxm2011\Trunk\zjgl\war\WEB
-INF\classes\com\toone\ipms\ipms-spring-global.xml]: Initialization of bean fail
ed; nested exception is org.hibernate.InvalidMappingException: Could not parse m
apping document from input stream
org.hibernate.InvalidMappingException: Could not parse mapping document from inp
ut stream
        at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:527
)
        at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPrope
rtiesSet(LocalSessionFactoryBean.java:683)


xml配置文件如下:

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC 
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    
<hibernate-mapping>
<class name="com.toone.imps.st.station.model.PDA" table="IMPS_RE_PDA">
    <id name="id" type="java.lang.String" column="ID">
		<generator class="uuid.hex" />
    </id>
   <property
        name="stationId"
        type="java.lang.String"
        column="STATIONID"
        length="64"
    />
   <property
        name="pdaNo"
        type="java.lang.String"
        column="PDANO"
        length="50"
    />
</class>
<query name="getPDAsByStationId">
	from PDA c
	where c.stationId = :stationId
</query>
<query name="getRecordCountByPDANo">
	select count(*) as recordCount from PDA c
	where c.pdaNo = :pdaNo
</query>
<query name="deletePDAsByStationId">
	delete from PDA c
	where c.stationId = :stationId
</query>
</hibernate-mapping>


看不出错在哪里吧,哈哈,真正的错误原因就在xml文件的第一行是空行,去掉空行就正确了,看命令行错误提示“Error parsing XML”后,只知道是这个配置文件的问题,查看字段和hql,没有找到原因(能找到才怪 ),确实很悲催吧。。
   发表时间:2012-02-03  
你的xml是从别处拷到你工程里面去的吧,可能是拷的时候带的不明符号
0 请登录后投票
   发表时间:2012-02-03  
第一行是纯空格应该是不会有问题的吧
最大可能是空白里面包含不可见的特殊字符
我就遇到过,换好几个编辑器才格式化正确
0 请登录后投票
   发表时间:2012-02-03  
应该有什么不可见字符吧,曾经被一个全角空格搞疯的苦逼程序员飘过
0 请登录后投票
   发表时间:2012-02-03   最后修改:2012-02-03
UE切换到16进制看一下空行?
Editplus另存UTF-8?
0 请登录后投票
   发表时间:2012-02-05  
<?xml version="1.0" encoding="utf-8"?>之前不能有空格或空行
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics