Problems Using Spring Hibernate

I have been using Spring JDBC with great success, but I have a lot of problems with this project. I will post links to the code here (this is just a small and dumb project to check if I can run it and run it so that I can use Hibernate in the future):

xml-file: http://codepaste.net/uw19zc

main-file: http://codepaste.net/iks1cp

I get a lot of errors like

[Fatal Error] bean2.out.xml:1:1: Premature end of file. 13:21:39,471 FATAL [main] Main - getAssociatedStylesheets failed 

and I did not create a.out.xml file.

+8
java spring hibernate
source share
3 answers

This error occurs due to incorrect parsing of the XML file. Using Eclipse to test it gives an error:

cvc-complex-type.2.3: Element 'beans' cannot have the [children] character because the type content of the type is only an element.

There seems to be some kind of weird character between one or many of these <bean> declarations. Have you copied this text from another place?

Remove all spaces and newlines between the <bean> definitions and return them to your editor.

UPDATE Copying and pasting in notepad ++ the text in the encoding you provided and setting the encoding for UTF-8 showed these characters in empty lines: xA0 . This is the standard Unicode translation for &nbsp; . This is likely to cause this problem.

This confirms 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> 
+41
source share

If you are using Linux, use cat -v file-name.xml to detect special "invisible" characters, such as "M-BM-" in your XML file

+7
source share

Sometimes there are hidden characters in dependencies or some bean definitions that you copy from some training website. best way to find out these hidden characters:

ctrl + shift + F

this will format your document and you will see a hidden character between some of the `

+2
source share

All Articles