These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Need help in setting up hibernate
PostPosted: Fri Dec 17, 2010 12:49 am 
Newbie

Joined: Fri Dec 17, 2010 12:36 am
Posts: 2
I need some help in setting up Hibernate to work with my DB. I have installed eclipse and mysql and written a simple program to store a table in the db. But the database connection is failing when I run my program it gives the below error message.

Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'anandi'@'localhost' (using password: YES)"
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1997)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:1906)
at com.mysql.jdbc.MysqlIO.secureAuth411(MysqlIO.java:2520)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:817)
at com.mysql.jdbc.Connection.createNewIO(Connection.java:1786)
at com.mysql.jdbc.Connection.<init>(Connection.java:450)

I am using the below configuration file.
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/contact</property>
<property name="hibernate.connection.username">anandi</property>
<property name="hibernate.connection.password">anandi</property>
<property name="hibernate.connection.pool_size">10</property>
<property name="show_sql">true</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.hbm2ddl.auto">update</property>
<!-- Mapping files -->
<mapping resource="contact.hbm.xml"/>

I have installed mysql where there is a database called contact and also it has a table called contact. Also the username and password I have provided in the above file is correct and the database is running. Still I am getting the above error. Can anyone guide me as to what might be the problem ? Any help would be highly appreciated.


Top
 Profile  
 
 Post subject: Re: Need help in setting up hibernate
PostPosted: Fri Dec 17, 2010 3:07 am 
Regular
Regular

Joined: Fri Aug 06, 2010 1:49 am
Posts: 102
Location: shynate26@gmail.com
Check your firewall is turned on. If so kindly allow an exception to mysql. First test your connection from third party tool like SQLyog.

_________________

Cheers!
Shynate
mailto:shynate26@gmail.com
www.CSSCORP.com


Top
 Profile  
 
 Post subject: Re: Need help in setting up hibernate
PostPosted: Fri Dec 17, 2010 3:20 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
This is not a firewall problem. The error message is typical for MySQL when you can connect to the server but the account doesn't exist or if the account is not allowed to connect to the specified database from the a given host. You need to connect to the MySQL server as an admin and issue something like:

Code:
GRANT ALL ON `contact`.* TO 'anandi'@'localhost' IDENTIFIED BY 'anandi';


You may want to have less permissions than ALL, but that is what I usually have on my development box.

As an alternative you may try different host names in the connection URL. Sometimes it helps to use the real host name or ip address. It all depends on which permissions you have granted to the account.


Top
 Profile  
 
 Post subject: Re: Need help in setting up hibernate
PostPosted: Fri Dec 17, 2010 12:38 pm 
Newbie

Joined: Fri Dec 17, 2010 12:36 am
Posts: 2
Hello,

Thank you very much for your help. That did the trick and the exception is gone.
However, I am facing a different issue now. The program that I have written is to insert a row in the contact database which has a table called contact. When I execute the program, it runs without any errors and gives the following output --

Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)

However, when I actually do a select * from contact; in mysql, I am not able to see the entries I entered through Hibernate. This is a bit surprising because there are no exceptions when I run my program. Any ideas on what I am missing. I really appreciate your help in getting this resolved.

Below is the code:
public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
Contact contact = new Contact();
contact.setId(1);
contact.setFirstName("asdad");
contact.setLastName("Kumar");
contact.setEmail("deepak");
session.save(contact);
}catch(Exception e){
System.out.println(e.getMessage());
e.printStackTrace();
}finally{
session.flush();
session.close();

}

}


Top
 Profile  
 
 Post subject: Re: Need help in setting up hibernate
PostPosted: Fri Dec 17, 2010 1:42 pm 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
That is probably because your code is lacking transaction management. Start by reading http://docs.jboss.org/hibernate/core/3. ... emarcation for a few code examples.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.