1

Hi I am new to java I am trying to do hibernate in eclipse this is my configuration file Hibernate.cfg.xml I edited it in note pad and copied it my app

<!DOCTYPE hibernate-configuration PUBLIC  
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"  
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">  

<hibernate-configuration>  
    <session-factory>  
        <property name="hbm2ddl.auto">update</property>  
        <property name="dialect">org.hibernate.dialect.SqlServerDialect</property>  
        <property name="connection.url" value="jdbc:sqlserver://localhost;databaseName=empDb;instanceName=MSHassan"/>  
        <property name="connection.username">hmohamed</property>  
        <property name="connection.password">Kocroc1234</property>  
        <property name="connection.driver_class">com.microsoft.sqlserver.jdbc.SqlServerDriver</property>  
    <mapping resource="employee.hbm.xml"/>  
    </session-factory>  
</hibernate-configuration>

I am getting error Cannot parse configuration file Hibernate.cfg.xml

1
  • Please, it's 2014 - use annotations! Commented Sep 25, 2014 at 20:28

1 Answer 1

1

You need to change:

<property name="connection.url" value="jdbc:sqlserver://localhost;databaseName=empDb;instanceName=MSHassan"/>

to:

<property name="connection.url">jdbc:sqlserver://localhost;databaseName=empDb;instanceName=MSHassan</property>

The former variant is valid for JPA (in persistence.xml), while the latter is Hibernate cfg specific.

Sign up to request clarification or add additional context in comments.

5 Comments

I made change but still get ....jdbc ....class not found I have added sqljdbc4.jar to jar files and set the classpath to its location classpath c:\temp\sqljdbc4.jar
@kobosh, if you add the JAR file to classpath in eclipse and then running the program from eclipse itself without deploying the code to any server then you will not get any exception. Please add more details on exactly what you are trying to do.
That's a different question. Mark this one as answered and ask a new one regarding your new exception.
but a lot needed to make it work! first add both jdbc.jar to classpath and to build path and added sqljdbc_auth to path and sqljdbc_auth.dll to jdk directory and used sql configuration manager to enable tcp/ip and assign port 1433 and it is important to create the database and also add eclipse to firewall
I never attempt to configure projects in my IDE. I always use the project build tool, like Maven.

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.