Hibernate of pupils inserting data to modify data using the implementation of database default values

Source: Internet
Author: User

Recently in writing a case, timed tasks to update the database operation, Nonsense said, on the code:

1@Component ("Taskjob")2  Public classTaskjobextendsHibernatedaosupport {3     4 @Resource5     Privatesessionfactory sessionfactory;6 7 @PostConstruct8      Public voidinit () {9 setsessionfactory (sessionfactory);Ten     } One      A@Scheduled (cron = "0 0/1 * * *?")) - @Transactional -      Public voidJobl ()throwsinterruptedexception { theSystem.out.println ("task begins execution ....")); -          This. Gethibernatetemplate (). Execute (NewHibernatecallback () { -  -              PublicObject Doinhibernate (Session session) +                     throwshibernateexception { -Session.createsqlquery ("TRUNCATE TABLE tm_org"). executeupdate (); +                 return NULL; A             } at         }); -System.out.println ("Delete Complete ..."); -Thread.Sleep (1000); -         FinalFile File =NewFile ("C:\\users\\lhq\\desktop\\t1018.txt"); -BufferedReader reader =NULL; -         Try { inSystem.out.println ("read the contents of the file in the behavior unit, read a whole line at a time:"); -Reader =NewBufferedReader (NewInputStreamReader (NewFileInputStream (file), "UTF-8")); toString tempstring =NULL; +          //read one line at a time until NULL is read to the end of the file -              while((tempstring = Reader.readline ())! =NULL) { the                 Finalstring[] split = Tempstring.split ("\\s+"); *org org =NewOrg (); $Org.setorgcode (split[0]);Panax NotoginsengOrg.setorgname (split[1]); - //Org.setstatus ("0"); the                 if(split.length>3) { +Org.setuporg (split[3]); A                 } theOrg.setcreator ("Superuser"); +                  This. Gethibernatetemplate (). persist (org); -                  $             } $ reader.close (); -              -}Catch(FinalIOException E) { the e.printstacktrace (); -}finally {Wuyi             if(Reader! =NULL) { the                 Try { - reader.close (); Wu}Catch(FinalIOException E) { -                 } About             } $         } -     } -}

At the beginning of the operation, this line is not, because I set the default value in the database,

The console will give me an error:

In order to run the program, I put this line manually added, today carefully think, there should be a way to solve this problem, on the Internet to find more than N text, have not specifically found the implementation method, most of the configuration file form (this year who also use the configuration file, all with annotations), and then painstakingly found a solution:

So I divert, and I wrote, and I found out it was this:

A look to know is outdated method, for the execution of the program did not control him, run up also no problem, then I looked at the source found in the 4.1 version of the time removed:

Then I found a sentence on each of these fields:

It means to replace it with {} and change it to this:

No problem, of course.

is to share the experience and help the people in need to provide solutions.

Hibernate of pupils inserting data to modify data using the implementation of database default values

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.