3

I'm trying to delete the objects in the database.

My first attempt was:

 public void removeAll(){
    TypedQuery<anObject> query = em.createQuery(
            "DELETE FROM tablName",
            anObject.class);
    query.executeUpdate();
}

this gave me an exception so I had a look at the example on the objected site and updated my code to resemble theirs:

  public int removeAll(){
        int deleted = em.createQuery(
                "DELETE FROM tableName").executeUpdate();
    }

I'm getting the same exception:

com.objectdb.o._TransactionRequiredException: Attempt to run update query when no transaction is active

anyone know what I can do to solve?

MWiesner
  • 7,913
  • 11
  • 31
  • 66
null
  • 3,221
  • 6
  • 32
  • 74

1 Answers1

1

I've added an answer here just in case someone else stumbles across this and it might help.

I had forgotten to add @Transactional notation.

The final code snippet looks like:

   @Transactional
public void removeAll(){
    TypedQuery<anObject> query = em.createQuery(
            "DELETE FROM tableName",
            anObject.class);
    query.executeUpdate();
}
null
  • 3,221
  • 6
  • 32
  • 74