Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8196279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:25:46+00:00 2026-06-07T05:25:46+00:00

I’ve tried to use some beans programmed in scala in my Spring (v 3.1)

  • 0

I’ve tried to use some beans programmed in scala in my Spring (v 3.1) web application and have encountered strange problems when it comes to transactions.

I’ve setup a small but complete Spring application in Roo to show my problem. To be honest, I don’t have a clue why it is not working…

project --topLevelPackage com.app
jpa setup --provider ECLIPSELINK --database DERBY_EMBEDDED
entity jpa --class com.app.MyEntity
field string --fieldName title

Then I created the interfaces in java

package com.app;
public interface IScalaMainClass {
 void doSomething();
}

package com.app;
public interface IScala1 {
 void someMethod();
}

package com.app;
public interface IScala2 {
 void someMethod();
}

The implementations are created in Scala where Scala1 persists MyEntity and Scala2 makes a DELETE query:

package com.app

import org.springframework.transaction.annotation.Transactional
import org.springframework.stereotype.Repository
import org.springframework.beans.factory.annotation.Autowired

@Repository class ScalaMainClass extends com.app.IScalaMainClass {
 @Autowired var bean1: IScala1 = null
 @Autowired var bean2: IScala2 = null

 @Transactional def doSomething() = {
  bean1.someMethod()
  bean2.someMethod()
 }
}


package com.app

import org.springframework.stereotype.Repository
import javax.persistence.{EntityManager, PersistenceContext}

@Repository class Scala1 extends com.app.IScala1 {
 @PersistenceContext var em: EntityManager = null

 def someMethod = {
  val e = new MyEntity
  em persist e
 }
}


package com.app

import org.springframework.transaction.annotation.Transactional
import org.springframework.stereotype.Repository
import javax.persistence.{EntityManager, PersistenceContext}

@Repository class Scala2 extends com.app.IScala2 {
 @PersistenceContext var em: EntityManager = null

 @Transactional def someMethod = {
  val q = em createQuery "DELETE FROM MyEntity"
  q executeUpdate
 }

}

Finally the test in Java is created which executes the IScalaMainClass:

import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.transaction.TransactionConfiguration;
import org.springframework.test.annotation.Rollback;
import org.springframework.beans.factory.annotation.Autowired;

import org.junit.runner.RunWith;
import org.junit.Test;
import org.junit.Assert;

import com.app.IScalaMainClass;

@ContextConfiguration(locations = "classpath:/META-INF/spring/applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
@TransactionConfiguration(defaultRollback = false)
public class AppTest {
 @Autowired private IScalaMainClass smc;

 @Test public void testIt() {
  smc.doSomething();
 }
}

If you now add the scala dependencies to pom.xml and do “mvn test” you will receive

javax.persistence.TransactionRequiredException: 
Exception Description: No transaction is currently active
...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T05:25:49+00:00Added an answer on June 7, 2026 at 5:25 am

    You need to be very careful when you look to Spring support for Transaction and other Aspect-oriented features.

    • Autowiring an immutable field is not possible: autowiring is a pattern which sets up dependency after initialization, val is an immutable property which cannot be changed after initialization

    • As you can read in the documentation, Spring AOP support is not based on bytecode weaving and it is purely implemented in Java: http://static.springsource.org/spring/docs/3.0.x/reference/aop.html

    This means that only beans which are created through Spring IoC could benefit of Spring AOP support.

    If you look in the introduction of the chapter you can read:

    AOP is used in the Spring Framework to…

    … provide declarative enterprise services, especially as a
    replacement for EJB declarative services. The most important such
    service is declarative transaction management.

    So if your bean is not created through Spring, you will not have spring transaction support available.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.