java - Hibernate not save Entity to oracle db -
I have created a small crude app using hibernate with struts2, spring, oracle db Adding Mathos to Action Class
public string ads () throws exceptions {t.setAO_CreatedBy ("me"); T.setAO_Name ("OK"); Orgdao.addOrg (t); // emplist = empdao.showEmployuee (); Return success; } Entity class for the exam:
@Entity @Table (name = "test") Public class test {@Id @Column (name = "AuUID") @Sewense Generator (name = "sequence organizer", sequence name = "SEQ_AT_ORGANISATION", allocation size = 1) @ Generated Values (strategy = generation type, sequence, generator = "sequence generation maker") Private int AO_ID; @column (name = "AO_name") private string AO_Name; @colom (name = "AO_CreatedBy") private string AO_CreatedBy; Public int getAO_ID () {return AO_ID; } Public Zero set AO_ID (int aO_ID) {AO_ID = aO_ID; } Public string getAO_Name () {return AO_Name; } Public Zero Set AO_Name (string aO_Name) {AO_Name = aO_Name; } Public string getAO_CreatedBy () {AO_CreatedBy; } Public Zero Set AO_CreatedBy (string aO_CreatedBy) {AO_CreatedBy = aO_CreatedBy; }} DAO method:
Public Zero addOrg (Test T) {//System.out.println""save: "+ org); Session session = null; Session = sessionfactory.open session (); {System.out.println ("Try save before:" + t.getAO_ID ()); Session.save (t); System.out.println ("after saving:" + t.getAO_ID ()); } Hold (exception e) {e.printStackTrace (); } I did not get any errors and the data has not been DB. I tested this code with mysql and it works fine, i think this problem is way out of the way with this sort of sequence.
Before saving: 0 Hibernate:
SEQ_AT_ORGANIZATION.nextval select from double < / pre> After saving: 1
Can you try
Public Zero addOrg (Test T) {//System.out.println""save: "+ org); Session session = sessionfactory.open session (); Transaction tx; Try {Tx = session.beginTransaction (); session.save (t); tx.commit (); System.out.println ("after saving:" + t.getAO_ID ()); } Hold (exception e) {if (tx! = Null) tx.rollback (); E.printStackTrace (); } Finally {session.close (); }
Comments
Post a Comment