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

  • Home
  • SEARCH
  • 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 9226859
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:55:48+00:00 2026-06-18T04:55:48+00:00

Following Entity throws and Error when deleting: Entity: @Entity @NamedQueries({ }) public class Server

  • 0

Following Entity throws and Error when deleting:

Entity:

@Entity
@NamedQueries({
})
public class Server {
   //some attributes
}

I have following quite simple JUnit test that performs the following operations:

  1. Entity Server is created
    @Transactional
    public class ServerDao {
    public Server update(Server entity, long userId) {
        entity.setDeleted(false);
        if (entity.getId() > 0) {
            if (userId > 0) {
                entity.setUpdated(new Date());
                entity.setUpdatedby(usersDao.get(userId));
            }
            em.merge(entity);
        } else {
            if (userId > 0) {
                entity.setInserted(new Date());
                entity.setInsertedby(usersDao.get(userId));
            }
            em.persist(entity);
        }
        return entity;
        }
    }
    
  2. Entity Server is deleted

    … same Dao

    public void deleteHardJUnit(Server entity) {
        em.remove(entity);
    }
    

    This will throw an exception like:

org.apache.openjpa.persistence.ArgumentException: You cannot perform
operation delete on detached object
“org.apache.openmeetings.persistence.beans.basic.Server-1”.

If I change the delete method to:

public void deleteHardJUnit(Server entity) {
    if (entity.getId() > 0) {
        em.refresh(entity);
        em.remove(entity);
    }
}

Everything “seems” to work as expected, no exception is thrown and the record is deleted from the database.

However I am not sure what this should mean, do we really need to refresh every entity before deleting it? Cause I have been using EntityManager.delete a number of times before without the need to refresh the entity.

  • 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-18T04:55:49+00:00Added an answer on June 18, 2026 at 4:55 am

    Assuming you’re using Spring’s @Transactional annotation, it can’t intercept calls coming from within an instance of the annotated object (due to Spring’s use of dynamic proxies for AOP and method interception). Try calling from a service layer and annotating the method there.

    If you’re not using Spring, then you likely want to be using @TransactionAttribute, which is the analagous Java EE annotation.

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

Sidebar

Related Questions

I have the following mapping @Entity @SequenceGenerator(name=sacpSequenceGenerator, sequenceName=SACP_SEQ) public class Sacp { private Integer
I have the following classes: import play.db.ebean.Model; import javax.persistence.*; @Entity public class A extends
I have the following entity with the following relation: @Entity @Table(name = bpr_user) public
I have the following entity class : @Entity @Table(name = THE_TREE, catalog = ,
I have an entity mapped as following: @Entity @Table(name = Groups) @IdClass(value = GroupId.class)
I have a JPA entity bean similar to the following: @Entity class License {
Consider the following code: @Entity @Table(name = a) public class A implements Serializable {
I have an abstract class that looks as follows. public abstract class Entity<PK extends
I have the following Entity Framework model: It's a very simple model and was
I have the following Entity: @Entity @Table @NamedQuery(name = Constants.FINDALLFINDERNAME, query = Constants.FINDALLQUERY) public

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.