Problems converting XML to Java when using hibernate


So I am having issues trying to convert XML into Java for a connection. Below is my code. I was wondering if anyone could help me figure it out.

Here is the XML FIle.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
    "-//Hibernate/Hibernate Configuration DTD//EN"

		<property name="hibernate.dialect">org.hibernate.dialect.SQLServer2012Dialect</property>
		<property name="hibernate.connection.driver_class"></property>
		<property name="hibernate.connection.url">jdbc:sqlserver://; </property>
		<property name="hibernate.connection.database">test1</property>
		<property name="hibernate.connection.username">test@test</property>
		<property name="hibernate.connection.password">123456789</property>
		<property name="hibernate.show_sql">true</property>
		<property name="">update</property>
		<mapping class="main.S"/>
		<mapping class="main.C"/>
		<mapping class="main.D"/>
		<mapping class="main.P"/>
		<mapping class="main.E"/>

Here is my attempt at converting.

			String host = "jdbc:sqlserver://";
			String uName = "test@test";
			String uPass = "123456789";
			Connection con = DriverManager.getConnection(host,uName,uPass);
		catch (Exception err)

As you can see Im quite new to this. Any pointers would help.


So, what is it that you are trying to convert from XML to Java?

The second code snippet is just a JDBC connection acquisition code. The question is why you’d want to do that when you can have Hibernate do that for you?

I am trying to add the xml code inside my main java class file. Is there a way hibernate can do that for me?

Check out the Getting Started Guide.

1 Like

Thanks. I found out the real issue is trying to run the. Java file. I’m getting "error: package javax. Persistence does not exist.

I tried adding this in POM but no luck

org.hibernate hibernate-core 4.3.9.Final

Also added this

javax.persistence persistence-api 1.0.2

Don’t use these older versions of Hibernate and JPA. Use the latest ones.

And use Maven for dependency management. Just read the Hibernate docs and you’ll know what to do.