How to remove an extra item from a collection of items in jpa

I am using jpa 2.0 and I have the following object:

@Entity
public class Folder{

    @ElementCollection
    @CollectionTable(name="folder_files")
    private Set<String> files;      
    // .....
 }

Given the file name, I would like to delete all entries where the files == theGivenFileName. In sql, it will be something like this:

Delete from folder_files where files = XXX

Is there any way to fulfill this request using api criteria? If not, is there a way to execute this query using jpql?

UPDATE: I think my question was not clear enough: Since jpql uses entities (not tables), I cannot just execute the sql written above, since I use @ElementCollection. I do not know how to handle this variable or even deal with it. I would like to delete all entries in this collection (in my case, files) that contain the given value from all entities. Is it possible to use jpql criteria or (even better) -api?

+3
3

, .

query = em.createQuery("SELECT i FROM Item i WHERE UPPER(i.name) LIKE :keyword ");
query.setParameter("keyword", "%" + keyword.toUpperCase() + "%");

,

https://forums.oracle.com/forums/thread.jspa?threadID=423742

:

@Noam : API

List cats = sess.createCriteria(Cat.class)
    .add( Restrictions.like("name", "Fritz%") )
    .add( Restrictions.between("weight", minWeight, maxWeight) )
    .list();

:

http://ctpconsulting.github.com/query/1.0.0.Alpha3/criteria.html

http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/querycriteria.html

+1

Delete FROM Entity, , .

SQL-, OneToMany Entity.

+1

. JPQL , DELETE . JPA 2.0:

( , ).
...
delete_statement:: = delete_clause [where_clause]
delete_clause:: = DELETE FROM entity_name [[AS] ident_variable]

API . CriteriaQuery - .

SQL.

+1

All Articles