Multiple labels on this line when using @Transactional

eg:

@Transactional public boolean addPersonToDb(Person p) { // message on this line //some logic } 

The code compiles and runs without problems.

Message itself: several markers on this line

  • implements

com.pname1.pname2.pname3.pname4.PersonDAO.addPersonToDb

  • recommended

org.springframework.transaction.interceptor.TransactionInterceptor.invoke (org.aopalliance.intercept.MethodInvocation)

I can’t understand if this is a mistake or just a message looking at other topics that people perceive as a mistake. I am just worried if my transactions are working.

Well, a class implements an interface and its method annotated as transactional, is there something wrong with that?

Update: some minor errors have been resolved, the web application is working, but I still get this message (not in the stack trace, but at the line breakpoint):

recommended by org.springframework.transaction.interceptor.TransactionInterceptor.invoke (org.aopalliance.intercept.MethodInvocation)

Current situation:

  @Transactional public void registerNewUser(Person p) { // this gives message on line breakpoint - advised by ...; AND this method is implemented by interface pd.addPersonToDb(p); } @Transactional public void blabla(Person p){ // this does not, as expected; AND it is not in interface } 

Do my transactions work or not? (I have no exceptions and web application launches and the methods work)

I can’t understand if this message was an error or not?

+4
source share
3 answers

The problem with multiple markers is not a problem at all; it is purely informational. (The method is part of an implementation of an interface or abstract method that you probably already knew, and it was intercepted by the AOP due to @Transactional annotation. I hope this does not surprise you ...)

The error is that the class you are commenting does not implement the appropriate interface (or interfaces), which is necessary to use the built-in JDK proxy mechanism to place AOP hooks in place in the bean. (Bean - level interceptors are executed through a proxy object that applies transactional behavior and then delegates the real object.) The JDK proxy mechanism only works with interfaces; intercepting something else requires a different approach.

Two possible fixes for this are:

  • Add the bean class to the appropriate interface, which has all the methods of your class marked as @Transactional .
  • Add cglib as a dependency that Spring uses to dynamically write classes that do the interception. (This is smart stuff.)

You only need to use one of these fixes, and the second is very simple if you use a build system such as Maven; just update the dependencies. (Also, avoid making calls to intercepted methods with this , explicit or not. These are side effects of intercepting AOPs.)

+5
source

I had the same red marks next to the method signature with the @Transactional annotation above.

 @Override @Transactional public void updateBook(Book book) { bookDao.updateBook(book); } 

The reporting of such markers was as follows:

A few tokens on this line - implements bookmanager.service.BookService.updateBook - recommended org.springframework.transaction.interceptor.TransactionInterceptor.invoke (org.aopalliance.intercept.MethodInvocation)

My fix is ​​that I replaced this @org.springframework.transaction.annotation.Transactional annotation with the following @javax.transaction.Transactional annotation.

I use the Hibernate framework to manage transactions in my application.

Hope this helps too.

+2
source

Your transactions will work if everything else is correct. The “consultation” here is purely informative and shows that your method is recommended using the spring TransactionInterceptor.invoke method.

A problem with several markers appears when you implement something, because there is two information: first it is “recommended”, and secondly, this method implements something.

If you are not sure, I suggest you write an integration test and test the changes in the database. But you don’t have to do anything, your code will work as it is. (If, as I said, everything else is true.)

+1
source

Source: https://habr.com/ru/post/1382502/


All Articles