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?