2

I'm trying to connect to an SQL Server database using Hibernate in Java. My hibernate.cfg.xml file looks like this:

<hibernate-configuration>   
<session-factory>  
    <property name = "hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
    <property name = "hibernate.connection.driver_class">com.microsoft.sqlserver.jdbc.SQLServerDriver</property>
    <property name = "hibernate.connection.url">jdbc:sqlserver://*******.database.windows.net:1433;databaseName=*******;</property>
    <property name = "hibernate.connection.username">*******@******</property>
    <property name = "hibernate.connection.password">**********</property>
    <property name = "hibernate.show_sql">true</property>
</session-factory>
</hibernate-configuration>

After trying to run the app, I get the following error:

Exception in thread "AWT-EventQueue-0" org.hibernate.internal.util.config.ConfigurationException: Unable to perform unmarshalling at line number 9 and column 23 in RESOURCE hibernate.cfg.xml. Message: cvc-complex-type.2.3: Element 'session-factory' cannot have character [children], because the type's content type is element-only.

Without using an ORM, I tried using the following connection string, and everything worked just fine:

"jdbc:sqlserver://*******.database.windows.net:1433;" +
"database=*****;" +
"user=*****@*******;" +
"password=********;" +
"encrypt=true;" +
"trustServerCertificate=false;" +
"hostNameInCertificate=*.database.windows.net;" +
"loginTimeout=30;"

The database is on MS Azure. Could someone help me with hibernate configuration? Is it possible to configure hibernate using a connection string, without the configuration file?

user2700896
  • 569
  • 1
  • 5
  • 14
  • This usually means you have an illegal character in your Xml somewhere. [This question](http://stackoverflow.com/questions/7835389/problems-using-spring-hibernate) might be related – rmlan Oct 11 '16 at 19:10
  • thx, I have retyped the xml file and now it has another error :) there was probably some random character because some parts of the config file were copy-pasted. – user2700896 Oct 11 '16 at 19:19
  • The config section that you provided hasn't any problem after my testing. There may be some mistakes in the other parts of your config file. Could you provide more about your config file? – johnny Oct 12 '16 at 07:54

0 Answers0