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: I am new user to hibernate and i am fresher can any bodyhelp
PostPosted: Wed Jul 18, 2007 1:07 pm 
Beginner
Beginner

Joined: Wed Jul 18, 2007 7:38 am
Posts: 23
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:3

Mapping documents:<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="roseindia.tutorial.hibernate.Contact" table="contact">
<id name="id" type="long" column="ID" >
<generator class="assigned"/>
</id>

<property name="firstName">
<column name="FIRSTNAME" />
</property>
<property name="lastName">
<column name="LASTNAME"/>
</property>
<property name="email">
<column name="EMAIL"/>
</property>
</class>


</hibernate-mapping>


Code between sessionFactory.openSession() and session.close():
package roseindia.tutorial.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
* @author Deepak Kumar
*
* http://www.roseindia.net
* Hibernate example to inset data into Contact table
*/
public class FirstExample {
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();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record1");
Contact contact = new Contact();
System.out.println("Inserting");
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("deepak_38@yahoo.com");
session.save(contact);
System.out.println("Done1");
}catch(Exception e){
System.out.println("Error"+e);
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}
}


Full stack trace of any exception that occurs:log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record1
Inserting
Done1
Exception in thread "main" org.hibernate.exception.GenericJDBCException: Cannot open connection
at org.hibernate.exception.ErrorCodeConverter.handledNonSpecificException(ErrorCodeConverter.java:92)
at org.hibernate.exception.ErrorCodeConverter.convert(ErrorCodeConverter.java:80)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:384)
at org.hibernate.jdbc.JDBCContext.connect(JDBCContext.java:141)
at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:88)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:73)
at org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:66)
at org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:130)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:1809)
at org.hibernate.persister.entity.BasicEntityPersister.insert(BasicEntityPersister.java:2171)
at org.hibernate.action.EntityInsertAction.execute(EntityInsertAction.java:46)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:136)
at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274)
at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:669)
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:37)
Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'root'@'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)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:411)
at java.sql.DriverManager.getConnection(DriverManager.java:525)
at java.sql.DriverManager.getConnection(DriverManager.java:140)
at org.hibernate.connection.DriverManagerConnectionProvider.getConnection(DriverManagerConnectionProvider.java:110)
at org.hibernate.jdbc.AbstractBatcher.openConnection(AbstractBatcher.java:381)
... 15 more


Name and version of the database you are using:My SQL Server 5.0

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Problems with Session and transaction handling?

Read this: http://hibernate.org/42.html


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 18, 2007 1:35 pm 
Newbie

Joined: Tue Dec 05, 2006 7:40 am
Posts: 14
you are sure about user and password ?

Code:
Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: YES)"


Top
 Profile  
 
 Post subject: Thanks
PostPosted: Wed Jul 18, 2007 1:55 pm 
Beginner
Beginner

Joined: Wed Jul 18, 2007 7:38 am
Posts: 23
ualex wrote:
you are sure about user and password ?

Code:
Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: YES)"

Thanks it was the exception
Now it runs perfectly but the values are not updated in the database table

My output is:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record1
Inserting
Done2
Hibernate: insert into contact (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)


Top
 Profile  
 
 Post subject: Re: Thanks
PostPosted: Wed Jul 18, 2007 2:17 pm 
Newbie

Joined: Tue Dec 05, 2006 7:40 am
Posts: 14
shiva_krish wrote:
ualex wrote:
you are sure about user and password ?

Code:
Caused by: java.sql.SQLException: Invalid authorization specification message from server: "Access denied for user 'root'@'localhost' (using password: YES)"

Thanks it was the exception
Now it runs perfectly but the values are not updated in the database table

My output is:

log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Inserting Record1
Inserting
Done2
Hibernate: insert into contact (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)


it is correct:

Code:
}catch(Exception e){
System.out.println("Error"+e);

//here rollback.

}finally{
// Actual contact insertion will happen at this step

// commit

session.flush();
session.close();

}



you forget commit.


Top
 Profile  
 
 Post subject: Thanks a Lot
PostPosted: Wed Jul 18, 2007 2:36 pm 
Beginner
Beginner

Joined: Wed Jul 18, 2007 7:38 am
Posts: 23
I have got solved this application and it is working perfectly
please help me in future bcoz i am fresher to this organization.


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.