-->
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.  [ 2 posts ] 
Author Message
 Post subject: problem in Insert into database
PostPosted: Tue Jan 29, 2008 2:09 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
My code is running fine...everything is o.k. But when i check my database .it reflects empty set...my code is written below


[java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[java] log4j:WARN Please initialize the log4j system properly.
[java] Inserting Record
[java] Done
[java] Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
BUILD SUCCESSFUL

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



public class FirstExample {

private Session session;

public static void main(String[] args) {
Session session = null;

try{
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.connection.driver_class", com.mysql.jdbc.Driver.class.getName());
configuration.setProperty("hibernate.connection.url",("jdbc:mysql://localhost:3306/hibernatetutorial"));
configuration.setProperty("hibernate.connection.username", "root");
configuration.setProperty("hibernate.connection.password", "test");
configuration.setProperty("hibernate.connection.pool_size", "1");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
configuration.addClass(Contact.class);
session = configuration.buildSessionFactory().openSession();

//"C:\\svn\\workspace\\hibernateTutorial\\cfg\\hibernate.cfg.xml"
// 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 Record");
Contact c = new Contact();
c.setId(3);
c.setFirstName("Deepak");
c.setLastName("Kumar");
c.setEmail("deepak_38@yahoo.com");
session.persist(c);
System.out.println("Done");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}

}


Top
 Profile  
 
 Post subject: Re: problem in Insert into database
PostPosted: Tue Jan 29, 2008 2:52 am 
Newbie

Joined: Fri Jan 25, 2008 8:32 am
Posts: 15
rhlpnt wrote:
My code is running fine...everything is o.k. But when i check my database .it reflects empty set...my code is written below


[java] log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
[java] log4j:WARN Please initialize the log4j system properly.
[java] Inserting Record
[java] Done
[java] Hibernate: insert into CONTACT (FIRSTNAME, LASTNAME, EMAIL, ID) values (?, ?, ?, ?)
BUILD SUCCESSFUL

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



public class FirstExample {

private Session session;

public static void main(String[] args) {
Session session = null;

try{
Configuration configuration = new Configuration();
configuration.setProperty("hibernate.connection.driver_class", com.mysql.jdbc.Driver.class.getName());
configuration.setProperty("hibernate.connection.url",("jdbc:mysql://localhost:3306/hibernatetutorial"));
configuration.setProperty("hibernate.connection.username", "root");
configuration.setProperty("hibernate.connection.password", "test");
configuration.setProperty("hibernate.connection.pool_size", "1");
configuration.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
configuration.addClass(Contact.class);
session = configuration.buildSessionFactory().openSession();

//"C:\\svn\\workspace\\hibernateTutorial\\cfg\\hibernate.cfg.xml"
// 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 Record");
Contact c = new Contact();
c.setId(3);
c.setFirstName("Deepak");
c.setLastName("Kumar");
c.setEmail("deepak_38@yahoo.com");
session.persist(c);
System.out.println("Done");
}catch(Exception e){
e.printStackTrace();
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}

}


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.