File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate.cfg.xml Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate.cfg.xml" Watch "hibernate.cfg.xml" New topic
Author

hibernate.cfg.xml

Manojkr Jadhav
Greenhorn

Joined: Sep 05, 2009
Posts: 7
Hi i am using SQL server 2005 and hibernate.
i am not able to insert any data to the database via my application. i am able to do so using a normal java application.

My hibernate.cfg.xml:

<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="hibernate.connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433/abc</property>
<property name="hibernate.connection.username">sa</property>
<property name="hibernate.connection.password">1234</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>

<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>
</session-factory>
</hibernate-configuration>

I have some error.....

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
JDBC Driver class not found: com.microsoft.jdbc.sqlserver.SQLServerDriver
Exception in thread "main" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:42)


How to resolve
veeresh soni
Greenhorn

Joined: Dec 10, 2009
Posts: 12
Check out the jar file for driver is having same driver .
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3816

Manojkr Jadhav wrote:i am able to do so using a normal java application.

With the same information related to driver as in hibernate.cfg.xml?

SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
xsunil kumar
Ranch Hand

Joined: Dec 14, 2009
Posts: 133
Jadhav, You are able to insert data using normal java program, it means that required jar is in classpath. Can you post location of mssql jar and hiberante related jars.

This type of issue can come due to class loader Hireachy. If your hibernate related jars are in upper level of class loader hireachy than your mssql jar, then you will get class not found exception.

Are you getting this exception in you editor or in server. Try to put sql server related jars in server lib directory.

-Sunil
Lucene china
Greenhorn

Joined: Dec 24, 2009
Posts: 4
don't be against the wall you can do it with above instructions


the sun is shunning,never give up.Go
Aby Krishna
Greenhorn

Joined: Jul 10, 2010
Posts: 14
quite old..but one of the problem in the original poster's code is that the driver class string is incorrect.

OP's driver class string: com.microsoft.jdbc.sqlserver.SQLServerDriver
Correct driver class string: com.microsoft.sqlserver.jdbc.SQLServerDriver
 
Don't get me started about those stupid light bulbs.
 
subject: hibernate.cfg.xml
 
Similar Threads
Hibernate without J2EE server
hibernate hello world
Doubt in Hibernate Sample Application
NullPointerException when run stand alone program
Problem with running my first Hibernate App