Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Data getting saved in session, but not being persisted in table.

 
mara thamizhan
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear dudes,
In persisting data in MySQL through hibernate, i'm using a simple java class , which creates an instance of my form , sets data , reads the configuration file, builds a session factory i.e. hibernate.cfg.xml , opens the session and save data .
Actually data was not inserted into the table eventhough i'm getting the message similar to that.

I created the database in MySQL initially.
message console:


My java application:"Testinghibernate.java"




Information.java


hibernate.cfg.xml:



Information.hbm.xml:
 
mara thamizhan
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will someone please reply?
 
jayachandra madopothula
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Possible corrections you have to have work
1.If you are working in eclipse please check the application structure
2. remove the and run it.
 
jayachandra madopothula
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

see the structure shown in the picture.

after arranging the whole structure just update resource mapping tag in hibernate.cfg.xml with absolute path of the hbm.xml
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hibernate requires a Transaction, and it to be commited to actually save stuff to the database. I do not see a

Transaction tx = session.beginTransaction();

and I also don't see a

tx.commit();

in your code.

Mark
 
Vikky Bali
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using Transaction it is working but Is this mandatory to use transaction in Hibernate ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic