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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:23:30+00:00 2026-05-26T19:23:30+00:00

I have a full Java EE web application with a presentation layer and a

  • 0

I have a full Java EE web application with a presentation layer and a database. I’m using derby with glassfish 3.1 and JPA to handle persistence. I’ve created a Read ok but now I’m having troulbe doing a Create and persisting to the database. I think I’m close but something is not right with the way I’m trying to do the create.

Here is my EAO code:

/**

 * Session Bean implementation class XRSSeao

 */

@Stateless

@LocalBean

public class XRSSeao {



@PersistenceContext

EntityManager em;

public XRSSeao() {}




    public void addEvent(String update){

    Feed feed = new Feed();

    feed.setStatus(update);

    feed.setId(2);

        em.getTransaction().begin();

            em.persist(feed);

            em.flush();

            em.clear();

        em.getTransaction().commit();

}

}

This will be called from another EJB. I also don’t want to have to set the ID since that is the primary key I want that generated whenever I call the persist method. The error I get when I test it is:

“Caused by: java.lang.IllegalStateException:
Exception Description: Cannot use an EntityTransaction while using JTA.”

If you don’t know what the problem is with this code but can provide an example of simple persisting with autogenerated primary key that would be just as helpful.

This is my read method that is working:

public String lastUpdate(){
    String resultString;
    Query q = em.createQuery("SELECT x FROM Feed x WHERE x.id = 1");
    List<Feed> ListofStatus =  q.getResultList();  //alternatively you can use getResultList() for non 1 object is expected. 
    Feed returnStatusObject = ListofStatus.get(0);
    resultString = returnStatusObject.getStatus();
    return resultString;

}

If I don’t need to use Transaction() I haven’t found an example online that does not use it for create.

  • 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-26T19:23:30+00:00Added an answer on May 26, 2026 at 7:23 pm

    You’re using EJB/JTA with transaction-type="JTA". The container will then manage the transactions itself. You can control the transactions by @TransactionAttribute and @TransactionAttributeType annotations on the EJB class/methods (which by default should however not be necessary). The tutorials which you’ve read apparently did not use EJB/JTA, but just application managed transactions with transaction-type="RESOURCE_LOCAL". You should read JPA tutorials which are targeted on use with EJB/JTA.

    To fix your problem -I assume that you want to keep using EJB/JTA-, replace

    em.getTransaction().begin();
    em.persist(feed);
    em.flush();
    em.clear();
    em.getTransaction().commit();
    

    by

    em.persist(feed);
    

    See also:

    • Java EE 6 Tutorial – Persistence – Managing Entities
      • Container-Managed Entity Managers
      • Application-Managed Entity Managers
    • Java EE 6 Tutorial – Transactions – Container Managed Transactions
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing my first Java EE web application using glassfish and netbeans. When I
I'm using Hibernate for a Java-based Web Application and want to add full-text search
In the application I'm developping (in Java/swing), I have to show a full screen
We have a Web Java based application running on JBoss with allowed maximum heap
I'm using JSF 2.0 with Facelets in a Java EE 6 application server (GlassFish
I have a Java EE web application that does not make use of EJBs.
I know about IIS being the web/application server. Why not have full fledge enterprise
Consider following assumptions: I have Java 5.0 Web Application for which I'm considering to
We are running an web application that is using Java 64bit 5 gigs of
I have registered my web application for use with oath2 using the following instructions:

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.