• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate sample done but no record inserted

 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all..
i am using good resource as first sample to lern hibernate, i use This URL
,the sample is great to read and understand as beginner..
this sample is compile and OK...

BUT No Record Inserted at my Contact Table,,,,Why??

regards
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you close or flush the Session? Did you commit the transaction? (if you used one?)
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi , yes i did, i flushed and closed the session by saying:


still no record added, can you help me?
[ December 19, 2006: Message edited by: Ala'a Hendi ]
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...and did you commit the transaction (if you used one)? Were there any exception messages?
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code:


anyway, there is no exception......
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you enabled Hibernate's debugging to see what SQL it generates? If not, try that.
 
Ayub ali khan
Ranch Hand
Posts: 394
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I executed the same code after the addition of transaction. Modify accordingly.

public class TestHibernate {

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();
org.hibernate.Transaction tx = session.beginTransaction();

//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
UAPUser user=new UAPUser();

//user.setId(2);
user.setPassword("abc");
user.setUserName("User1");
session.save(user);
tx.commit();

System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}

}
 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks...
now it works..
thanks very much
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic