使用Spring Hibernate的问题 [英] Problems using Spring Hibernate
问题描述
我一直使用Spring JDBC取得了巨大的成功,但是我在这个项目中遇到了很多麻烦。我会在这里发布代码链接(这只是一个小而愚蠢的项目,以测试我是否可以启动并运行,以便将来可以使用Hibernate):
xml-file: http://codepaste.net/uw19zc
main-file: http://codepaste.net/iks1cp
我收到了很多错误,比如
[致命错误] bean2.out.xml:1 :1:文件过早结束。
13:21:39,471 FATAL [main] Main - getAssociatedStylesheets失败
t创建了a.out.xml文件。
这个错误是由于对xml文件的解析不正确。
使用Eclipse验证它会给出错误:
lockquote
似乎在一个或多个那些< bean>
声明。你是否从其他地方复制过这些文字?
删除< bean>
定义之间的所有空格和换行符,并将其放回到您的编辑器中。
更新
复制&将记事本++粘贴到您提供的代码语言中,然后将字符集设置为UTF-8将这些字符显示为空行: xA0 。这是& nbsp;
的标准Unicode转换。这可能是造成这个问题的原因。
这证实了我的好处:
<?xml version =1.0encoding =UTF-8?>
< beans xmlns =http://www.springframework.org/schema/beans
xmlns:xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd\">
< bean id =dataSourceclass =org.apache.commons.dbcp.BasicDataSource
destroy-method =close>
< property name =driverClassNamevalue =com.mysql.jdbc.Driver/>
< property name =usernamevalue =HibernateDB/>
< property name =passwordvalue =java/>
< / bean>
< bean id =sessionFactory
class =org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean>
< property name =dataSourceref =dataSource/>
< property name =configurationClassvalue =org.hibernate.cfg.AnnotationConfiguration/>
< property name =annotatedClasses>
< list>
< value> hdao.HibernateObject< / value>
< / list>
< / property>
< / bean>< bean id =springHibernateOperatorclass =hdao.SpringHibernateOperatorImplementation>
< property name =sessionFactoryref =sessionFactory/>
< / bean>
< / beans>
I've been using Spring JDBC with great success but I am having alot of trouble with this project. I'll post the code links here(it's just a small and silly project to test if I can get it up and running so that I can use Hibernate in the future):
xml-file: http://codepaste.net/uw19zc
main-file: http://codepaste.net/iks1cp
I get tons of errors such as
[Fatal Error] bean2.out.xml:1:1: Premature end of file.
13:21:39,471 FATAL [main] Main - getAssociatedStylesheets failed
and I haven't created a.out.xml file.
This error is due to incorrect parsing of the xml file. Using Eclipse to validate it gives the error:
cvc-complex-type.2.3: Element 'beans' cannot have character [children], because the type's content type is element-only.
There appears to be some strange character in between one or many of those <bean>
declarations. Have you copied this text from somewhere else?
Remove all spaces and newline characters between <bean>
definitions and put them back with your editor.
UPDATE
Copying & pasting into notepad++ the text in the codepaste you provided, and setting the charset to UTF-8 showed these characters in the blank lines: xA0. This is the standard Unicode translation for
. This is likely to be the cause of this problem.
This validates ok for me:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/HibernateDB" />
<property name="username" value="HibernateDB" />
<property name="password" value="java" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
<property name="annotatedClasses">
<list>
<value>hdao.HibernateObject</value>
</list>
</property>
</bean><bean id="springHibernateOperator" class="hdao.SpringHibernateOperatorImplementation">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
</beans>
这篇关于使用Spring Hibernate的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!