Can you delete a detached entity using Hibernate directly in JBoss EAP?

Solution Unverified - Updated -

Issue

I have attached some examples containing both the executed code and the related log. These examples have been executed on Tomcat 6.0.29 using Hibernate 4.1.7-Final. As you can see, in each example, all detached entities have been deleted.

Nevertheless, I read another time in both EntityManager and Session javadoc.
While the EntityManager javadoc explicitly forbids to delete detached entities, the Session javadoc doesn't say anything about them:

EntityManager#remove
void remove(java.lang.Object entity)

    Remove the entity instance.

    Parameters:
        entity - entity instance 
    Throws:
        IllegalArgumentException - if the instance is not an entity or is a detached entity 
        TransactionRequiredException - if invoked on a container-managed entity manager of type PersistenceContextType.TRANSACTION and there is no transaction

Session#delete
void delete(Object object)

    Remove a persistent instance from the datastore. The argument may be an instance associated with the receiving Session or a transient instance with an identifier associated with existing persistent state. This operation cascades to associated instances if the association is mapped with cascade="delete"

    Parameters:
        object - the instance to be removed

Since Session javadoc doesn't say anything about detached entities I think that it's not allowed to delete them, but the implementation deletes such entities (at the least since Hibernate 3.3) as you can see in the examples.

So, independently from the standalone Hibernate implementation behaviour, can you confirm me that the Session API shouldn't allow to delete detached entities?

Environment

  • JBoss Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content