The entitymanager. persist () method of JPA cannot be saved to the database.

Source: Internet
Author: User

I encountered a small problem when I used JPA yesterday. entitymanager was injected through the @ persistcontext method. There is no problem in using entitymanager to query objects, but data cannot be saved to the database during persistence,ProgramNo exception is thrown. After a day, I always thought it was persistence. where is the XML file going wrong? Finally, I checked the information online and found the difference between JTA and resource_local in transaction-type. I thought that I did not add the @ transactional tag before calling the persis () method. Now the problem has been solved. I sincerely thank Baidu and Google for sharing their experience in solving the problem on the Internet!

 

Reprinted: The difference between JTA and resource_local is that one is declarative transaction management. The container takes care of the EJB method process that you added @ transactionattribut (XXXX) annotation, the other one needs to manually obtain a transaction handle from Em and use programming transaction management methods such as begin () and commit ().

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.