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 6176457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:06:22+00:00 2026-05-24T00:06:22+00:00

I have a method that transfers data from one database to another and in

  • 0

I have a method that transfers data from one database to another and in the process creates new tables in the target database. The method is part of a stateless EJB (Java EE 6, GF 3.1) so the container, by default, starts a distributed transaction when the method is called.

The data transfer process essentially runs as two separate steps 1. read from the source database 2. write to the target database. If the read step fails then I don’t want the write step to happen but if the write step fails and the read has been committed already I don’t really care – I’ll just throw the data away.

Initially I hit the problem that my data sources weren’t XADataSource’s so the container complained about that. I then converted them to XADataSource’s but it still failed because the write process (which is into a MySQL database) contains create table statements which cause an implicit commit and you can’t do that in a distributed transaction.

The solution I’ve finally come to is to mark transfer method as TransactionAttributeType.NOT_SUPPORTED and then place the read and write process into their own methods which are called by the parent transfer method.

My question though is this: do the read and write methods run inside their own transactions or does the NOT_SUPPORTED propagate to them? My guess is that they have an implicit TransactionAttributeType.REQUIRED and so will start their own transaction but I’m not sure and I think it’s important they are running inside a transaction.

Is this the best solution to this problem?

  • 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-05-24T00:06:23+00:00Added an answer on May 24, 2026 at 12:06 am

    The bigger question for separating the read and write steps is whether or not the write step should still be performed if some other thread/process is mutating the data that was obtained from the read step. In other words, are you sure that the read and write should not be in the same transaction? Perhaps you have some external guarantee that there won’t be problems writing the data separately.

    How are the read and write methods called? If they’re called as local methods, then the NOT_SUPPORTED will propagate. If they’re called through a session bean proxy object, then the default REQUIRED will apply:

    @Stateless
    @Local(MyIntf.class)
    public class MyBean {
        @EJB
        private MyIntf ivMyBean; // Self-injection
    
        @TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
        public void method() {
            // Use the injected proxy rather than "this.read()" to ensure that the
            // default REQUIRED transaction attribute is used for the DB operations.
            MyResults results = ivMyBean.read();
            ivMyBean.write(results);
        }
    
        public MyResults read() { ... }
        public void write(MyResults results) { ... }
    }
    

    It seems somewhat questionable that you have to create tables based on the read data. Is there really no way to do that as a separate operation? I would suggest an outer REQUIRED method that does the read operation, then calls a NOT_SUPPORTED method to create tables, and finally does the write operation in the same transaction as the read, which was temporarily suspended while the NOT_SUPPORTED method was running.

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

Sidebar

Related Questions

I have a method that creates a MessageDigest (a hash) from a file, and
I have a method that I'm writing that is calling another overloaded method inside
I have a desktop (winforms) application that uses a Firebird database as a data
I have an existing SQL Server database, where I store data from large specific
I have a new web app that is packaged as a WAR as part
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to
I have a method that can return either a single object or a collection
I have a method that takes an IQueryable. Is there a LINQ query that
I have a method that periodically (e.g. once in every 10 secs) try to

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.