Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate--->Sqlserver

 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure I can help, but I might if you tell me which line is throwing the NPE.
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am getting nullpointerexception like

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

 
Henrique Ordine
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Line 33 in FirstExample.java is an empty line. Maybe you should recompile your code?
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
there are some blank lines so it showed line no.33

Now its showing in line no.27 session.flush();
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Move these two lines. Place directly after call to save().

 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jimmy Clark wrote:Move these two lines. Place directly after call to save().


Why?
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not?
 
Ganeshkumar cheekati
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not working even i place these two lines after the session.save()
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 33
Google Web Toolkit Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check your logging. Hibernate configuration does not fail silently.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic