aspose file tools*
The moose likes Object Relational Mapping and the fly likes hibernate sample done but no record inserted Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate sample done but no record inserted" Watch "hibernate sample done but no record inserted" New topic
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: 379
    
    2
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: http://aspose.com/file-tools
 
subject: hibernate sample done but no record inserted
 
Similar Threads
Query returs empty list but getting results in TOAD
code for modification
Issue with Hibernate transaction in CMT
Query on JPA Annotation
hibernate update