MySQL Master/Slave Load Balancing with JPA and Spring

Category: Software | Tags: , , , , , , 9 comments »

9 Responses to “MySQL Master/Slave Load Balancing with JPA and Spring”

  1. Kev

    Very helpful, thanks.

  2. Sam Thomas

    Thank you for this. I’m trying to get this working for a non-JPA usecase and I can’t figure out how to get the connection using SessionFactory instead of EntityManager. Would you be willing to provide an example of the Aspect for that use case?

  3. Dragisa Krsmanovic

    Another way to do this is via connection pool hooks.

    In your hook code, you can always check if you are inside a read-only or r/w transaction using Spring TransactionSynchronizationManager

    I think this is a better approach then the one I initially suggested in my article.

  4. dustincg

    Dragisa, have you tried using the connection hooks? I tried it using BoneCP and the TransactionSynchronizationManager, however it doesn’t seem to work. Changing the connection to read only in onBeforeStatementExecute() doesn’t error, and the logical connection looks correct, but it also still reads from the master. If you could get the transaction information in checkOut() it would work, but the transaction isn’t active at that point.

  5. Dragisa Krsmanovic

    @dustincg It works fine with c3p0. I don’t see why it shouldn’t work the same way with BoneCP.

    It’s strange that you are seeing connection being checked out from pool before the Spring transaction has started. Spring transaction context is available inside a @Transactional method.

  6. Shridutt

    How to do MySQL Master/Slave Load Balancing with SpringBoot??

  7. Piotr

    Any better solutions to this problem? It seems to still be a problem with spring 4.3 and hibernate 4.3.

  8. Gyuseo Shim

    This article has helped a lot. thank you.

  9. davlee

    why can not see artical?


Leave a Reply



 

Back to top