| Author |
hibernate sample done but no record inserted
|
Alan Hermin
Ranch Hand
Joined: Feb 16, 2006
Posts: 290
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Did you close or flush the Session? Did you commit the transaction? (if you used one?)
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Alan Hermin
Ranch Hand
Joined: Feb 16, 2006
Posts: 290
|
|
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
Joined: Apr 14, 2004
Posts: 10336
|
|
|
...and did you commit the transaction (if you used one)? Were there any exception messages?
|
 |
Alan Hermin
Ranch Hand
Joined: Feb 16, 2006
Posts: 290
|
|
this is the code: anyway, there is no exception......
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Have you enabled Hibernate's debugging to see what SQL it generates? If not, try that.
|
 |
Ayub ali khan
Ranch Hand
Joined: Oct 20, 2005
Posts: 378
|
|
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(); } } }
|
SCEA part I,TOGAF Foundation
|
 |
Alan Hermin
Ranch Hand
Joined: Feb 16, 2006
Posts: 290
|
|
thanks... now it works.. thanks very much
|
 |
 |
I agree. Here's the link: jrebel
|
|
subject: hibernate sample done but no record inserted
|
|
|