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--->Sqlserver Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate--->Sqlserver" Watch "Hibernate--->Sqlserver" New topic
Author

Hibernate--->Sqlserver

Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
Hi,

I am trying to connect to sql server database from hibernate3 which i am doing it manually but not with eclipse.
As a result i am getting nullpointerexception like

before starting...
Exception in thread main java.lang.NullPointerException
at FirstExample.main(FirstExample.java:33)

while running the below program

jar files:
1)hibernate3.jar
2)hibernate-core.jar
3)jtds-1.2.2.jar



and

hibernate.cfg.xml file contains



and contact.hbm.xml file is


and
contact.java is



Can anyone tell me where i did mistake?

thanks in advance.


SCJP5 and SCWCD1.5
Think Twice Act Wise...
Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
I'm not sure I can help, but I might if you tell me which line is throwing the NPE.


J2EE Architect/Developer
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
i am getting nullpointerexception like

before starting...
Exception in thread main java.lang.NullPointerException
at FirstExample.main(FirstExample.java:33)

Henrique Ordine
Ranch Hand

Joined: Sep 03, 2004
Posts: 127
Line 33 in FirstExample.java is an empty line. Maybe you should recompile your code?
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
there are some blank lines so it showed line no.33

Now its showing in line no.27 session.flush();
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

So you have no session? What do the logs say regarding your Hibernate configuration? If you can't get a session, something is misconfigured there.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Move these two lines. Place directly after call to save().

Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Jimmy Clark wrote:Move these two lines. Place directly after call to save().


Why?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Why not?
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
Its not working even i place these two lines after the session.save()
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Jimmy Clark wrote:Why not?

Because its neither here nor there with regards to Ganeshkumar's problem; why do you think it would change the issue? If session is null when flush is called, it is also null when save is called. Also, moving it from the finally block will leave Sessions open if exceptions occur; where this code is currently is the best place for it.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Ganeshkumar cheekati wrote:Its not working even i place these two lines after the session.save()

What other errors do you have in the log? The session will be null if the configuration was wrong, so something is not right there. The Jar files you list for example look wrong.
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
Hi paul,
i am using three jars
1)hibernate3.jar
2)hibernate-core.jar
3)jtds-1.2.2.jar

to run this code and configuration file is



i am getting null value for session so Is there any problem in configuration file ?
Ganesh Shirsat
Ranch Hand

Joined: Jan 10, 2010
Posts: 32

Hi

have you tried this url using Connection object.

is it working fine.

jdbc:jtds:sqlserver://localhost:1433;DatabaseName=hibernatetutorial;SelectMethod=direct


according to jtds there is no selectMethod property.

selectMethod property are used in MS Jdbc

http://jtds.sourceforge.net/faq.html

please check that, is it working properly using Connection Object or not?.





Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

This is a good suggestion, though the error message that is occurring before your NullPointerException will tell you exactly what the issue is. If you could post that please?
Ganeshkumar cheekati
Ranch Hand

Joined: Oct 13, 2008
Posts: 362
I am able to connect to sqlserver using jtds driver with selectmethod property from my applications so i dont think that it is problem with selectmethod property.

After executing my program i am getting output as

before starting....

NullPointerException
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Check your logging. Hibernate configuration does not fail silently.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Hibernate--->Sqlserver