spring double-data-source development process encountered pit

Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/qq_28929579/article/details/84583693


Due to business needs, to connect the two data sources, the company should therefore double data frame into a packet source configuration. The following is a novice to avoid the pit experience. . .

java.lang.IllegalArgumentException: No persistence unit with name ‘xxx’ found

The company framework jar package turned out to be a single source of data, since data sources into a double, it is not very simple? The xml configuration persistenceUnitManager, entityManagerFactory, transactionManager, dataSource and transaction-manager are copied out of the name change, which entityManagerFactory of persistenceUnitName property is no longer a default becomes xxx, and also replicated on @PersistenceContext notes instead of good baseDao xxx, Here Insert Picture Description
and then start to pull on the error No persistence unit with name 'xxx' found. In addition to these two places, but also where the increase xxx? Baidu said that looking at META-INF / persistence.xml, the project did not Ah! Later, a fierce thought, the company may be in the framework of the jar package! ,,, we found out in the jar put under src, then follow add xxx, restart ok.

Only query can not be added or deleted?

With a good data source, you can develop a pleasant query is also a data log table to be inserted later, no response? Not being given? But dao Another data source can be inserted, then thought is not no configuration Arab affairs, but the service really add @Transactional, in this pit, @ Transactional default, which is the default data source management of affairs, with the other a dao certainly can not open the data source affairs, so @Transactional (value = "transactionManagerNew") is used to indicate a method in which the manager plus. Save successful run ok

Also you can not catch abnormal operation after the transaction is wrong?

Write a cron job to call a stored procedure and the results save the log table, of course, with a try to live that contains stored procedures, stored and processed in the field failed catch, no abnormal normal save. Seems right to do so, but when I changed the name of the stored procedure does not exist, will find that although catch live an exception, but the entire transaction is rolled back, and it leads not check insert log table, and met and https: / /bbs.csdn.net/topics/390688795 the same problems. After the test solution is as follows (dao into the transaction layer):
1. Create a new-Service, without @Transactional
2. In dao layer, two new classes, to invoke a stored procedure to update a log, two methods are head plus @Transactional.
3. In the method wrapped by try to call the new service, and then save the log method calls.

Guess you like

Origin blog.csdn.net/qq_28929579/article/details/84583693