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?

3
  • This usually means you have an illegal character in your Xml somewhere. This question might be related Commented Oct 11, 2016 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. Commented Oct 11, 2016 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? Commented Oct 12, 2016 at 7:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.