delete « Query « JPA Q&A





1. Order of Hibernate delete queries    stackoverflow.com

Here is my data model (simplified)

public class AddressBook {
 private List<Group> groups = new ArrayList<Group>();
 private List<People> peoples = new ArrayList<People>();

 @OneToMany(mappedBy = "addressbook", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
 @OnDelete(action ...

2. Java: Hibernate - Query to delete from multiple tables    stackoverflow.com

i have two tables connected by a foreign key with a one to many relation. in entity A i have the following :

@org.hibernate.annotations.Cascade( {
 org.hibernate.annotations.CascadeType.ALL,
 org.hibernate.annotations.CascadeType.DELETE_ORPHAN })
@OneToMany(mappedBy="monitoredFlight", fetch = FetchType.LAZY)
@OnDelete(action=OnDeleteAction.CASCADE)
private List<bTable> BTable ...

3. query must begin with SELECT or FROM: delete [delete    stackoverflow.com

I am using JPA in addition to spring(3.0.0.M4). While deleting multiple records using query.executeUpdate() i am getting the following exception.

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryException: query must begin ...

4. Hibernate; HQL; why does the delete query not work, but select does?    stackoverflow.com

I want to delete certain records from a table. These records have some child-records in other tables. In order to be able to delete the main records, I have to delete ...

5. Deleting orphans with JPA    stackoverflow.com

I have a one-to-one relation where I use CascadeType.PERSIST. This has over time build up a huge amount of child records that has not been deleted, to such an extend that ...

6. JPA Native Query delete in    stackoverflow.com

I try to delete a list of rows from a table using this Native Query:

@NamedNativeQuery(name="WebGroup.DeleteIn", query="DELETE FROM WebGroup WHERE WebGroup.GROUP_ID IN (:IDsList)" getEm().createNamedQuery("WebGroup.DeleteIn") ...

7. JPA 2 Delete/Insert order from Metamodel    stackoverflow.com

I'm trying to use the JPA2 metadata to figure out the order to insert/delete rows from a database so constraints are not an issue (to be used later in Java code). ...

8. Why does this HQL delete fail, when an HQL select with same terms works?    stackoverflow.com

Why does the following HQL query fail?

string hql = @"delete MyLog log
               where
     ...





10. Hibernate does delete and insert during a find.    coderanch.com

I try to figure out why hibernate does insertes and deletes while I'm actually doing a select. In our app. hibernate does a search on a user with a given username to retrieve the userobject (Hibernate.find()). During this search it does 4 selects, 1 delete(?!) and 2 inserts(?!). The usertable has a many-to-many connection with a grouptable. So when I retrieve ...

11. Hibernate (HQL Delete Query)    coderanch.com

Hi, Please help me in writing HQL delete query. My entity Class is like this public class FunctionResourcePermissionData implements java.io.Serializable { // Fields private FunctionResourcePermissionId id; private CompositeResourceData resourceObject; private FunctionData function; private String permissionCode; private Date recordCreationTimestamp; private String recordCreationUserId; private Date lastUpdateTimestamp; private String lastUpdateUserId; The Id class is public class FunctionResourcePermissionId implements java.io.Serializable { // Fields private Integer ...

12. Hibernate: Does not refresh after deletion    coderanch.com

Hi there. I have a parent and child relationship. If I delete the child, it does not reflect immediately in the application. I need to log-out and log-in back to the system to see the actual result. Here's the mapping in parent: No mapping is child since it`s a unidirectional. Thank you ...

14. Delete Query in hibernate doesnt work    coderanch.com

I am a newbie to hibernate 3...I have a problem associated with the hibernate delete query..... when i execute the delete query it returns a 'null'.... My program to delete the query is import org.hibernate.Query; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; public class DeleteHQLExample { public static void main(String[] args) { Session session = null; try { SessionFactory sessionFactory ...

15. Hibernate: IN clause when deleting    coderanch.com

Hello! I have an entity User: @Entity @Proxy(lazy=false) public class User{ @Id int id; protected String name; } I'd like to delete some users from a list of ids (List), so I tried to use the IN clause but ot didn't work. Neither I could use a Criteria. So what I did was to use the Criteria to make a select ...

16. Hibernate HQL Delete query problem    coderanch.com

Following are my entity classes: class SampleEntityA { private Long id; private List sampleEntitiesBList; private CustomEnumType customEnum; @Id @GeneratedValue(strategy = GenerationType.AUTO) @Column(name = "id") public Long getId() { return id; } public void setId(Long id) { this.id = id; } @OneToMany(mappedBy = "sampleEntityA") public List getSampleEntitiesB() { return sampleEntitiesBList; } public void setSampleEntitiesB(List sampleEntitiesBList) { this.sampleEntitiesBList = sampleEntitiesBList; } @Enumerated(EnumType.STRING) public ...





17. Extra inserts & deletes during select    forum.hibernate.org

18. Using Native SQL Query deletes the second level cache    forum.hibernate.org

Newbie Joined: Thu Jul 28, 2011 10:06 am Posts: 1 Hi, In our project, I observed that when we use Native SQL query for any DML statement, the entities in second level cache were evicted. Could someone please provide some insight into avoiding this scenario without any performance impact? From my analysis: When I used a profiling tool to identify the ...

19. Hibernate Criteria query returns deleted objects    forum.hibernate.org

createCriteria returns an object deleted by previous session.delete(). When we try to update object returned by createCriteria, this update fails. createCriteria should not return deleted objects (at least it was not in Hibernate 2) Hibernate 3.6.8 is used. Both session.delete() and createCriteria are in the same session and parts of the same transaction. Is it Hibernate bug? Any workaround for this ...

20. Delete by Named Query    forum.hibernate.org

21. problems with delete(query)    forum.hibernate.org

Please read the documentation and API Javadoc for Session.delete(): delete(String query) Delete all objects returned by the query. delete(String query, Object[] values, Type[] types) Delete all objects returned by the query. delete(String query, Object value, Type type) Delete all objects returned by the query. You use a query string like "from myClass foo where foo.someAttribute = ?" and then bind a ...

22. session.find after session.Delete problem    forum.hibernate.org

I have the following code: Code: Session session = null; try { // get factory and open session SessionFactory factory = HibernateConfiguration.getInstance().getFactory(); session = factory.openSession(); // create rule list Transaction ...

23. HQL Help with SELECT and DELETE    forum.hibernate.org

I have read through the documentation and posts, and I can't find what I need. I would like to execute SELECT * FROM table_name and DELETE FROM table_name. I have tried the following: find("SELECT * FROM table_name"); delete("SELECT * FROM table_name"); Can someone tell me what the equivalent HQL statements are? Thanks!

24. delete vs find+delete    forum.hibernate.org

public int delete(String query, Object[] values, Type[] types) throws HibernateException { if ( log.isTraceEnabled() ) { log.trace( "delete: " + query ); if (values.length!=0) log.trace( "parameters: " + StringHelper.toString(values) ); ...

25. Query Cache invalidation on insert/delete?    forum.hibernate.org

Are cached queries supposed to be invalidated when hibernate inserts or deletes a persistent object? If not, it sure makes the query cache less transparent than it could be. I suppose I can think of instances when it'd be preferable to keep a stale query around for performance reasons rather than return stale data, but in my mind, those are exceptions ...

26. All HQL delete is preceded by a select?    forum.hibernate.org

02:37:35,796 INFO [STDOUT] Hibernate: select sistema0_.id as id, sistema0_.descricao as descricao, sistema0_.nome as nome, sistema0_.operadorInclusao as operador4_, sistema0_.data HoraInclusao as dataHora5_, sistema0_.operadorAlteracao as operador6_, sistema0_.dataHoraAlteracao as dataHora7_, sistema0_.versaoRegistro as versaoRe8_ from Sistema sistema0_ wher e (sistema0_.id=10 ) 02:37:35,843 INFO [STDOUT] Hibernate: select perfis0_.id as id__, perfis0_.sistemaId as sistemaId__, perfis0_.id as id0_, perfis0_.descricao as descricao0_, perfis0_.nome as nome0 _, perfis0_.sistemaId ...

27. Query Delete    forum.hibernate.org

Hi, I need to fire SQL "DELETE" Statements from our Application. I would most preferably do this using NamedQuerys. This is not possible currently right? Is the a timescale of this feature? Is there an alternative way how to do this? Maybe anyone can explain to me how to fire a direct JDBC-Query using the Hibernate Session Connections? Regards, Alex

28. delete(Query) not available on Session interface?    forum.hibernate.org

I am new to Hibernate, but I think I am getting along fairly well for only using it for a week. I like the idea of storing queries in the *.hbm.xml files, but I can't figure out why I can't call session.delete() using a Query object. All signatures only accept strings. Thanks! DeVon

29. session.delete(query)    forum.hibernate.org

Looks like you are having fun learning too! Here's what I did... I did a query.list() to retrieve a list of all objects that satisfy the query, then call session.delete(Object) on each of them. If you're not familiar with query.list, you can also use either session.find() for a full list of objects all in memory at the same time, or session.iterate() ...

30. HQL Delete Query with Named Parameters    forum.hibernate.org

31. Hibernate is reexecuting a delete query    forum.hibernate.org

I having trouble finding out what I am doing wrong. I'm trying to delete an object using session.delete, and it fails because this object is refered by other objects. I catch the exception thrown in commit, and I rollback the transaction. After that, my app is still running, but anything I do, like an insertion, at commit time hibernate tries again ...

32. Select 'hibernate-2.1', Press 'Delete'    forum.hibernate.org

33. deleting with query    forum.hibernate.org

bertrand wrote: My two cents... (not tested ;) - why don't you just do: Code: query.uniqueResult() Bertrand, you'll have to show me what you mean; I tried 2 or 3 variations of query.uniqueResult() and couldn't get it to work. Simon, This has been on my mind because I'm trying to get my head around what Hibernate is all about. Coming from ...

34. No persister exception upon delete with query    forum.hibernate.org

Exception: No persister for: java.lang.String org.springframework.orm.hibernate.HibernateSystemException: No persister for: ja va.lang.String; nested exception is net.sf.hibernate.MappingException: No persis ter for: java.lang.String net.sf.hibernate.MappingException: No persister for: java.lang.String at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryI mpl.java:344) at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java: 2686) at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2693) at net.sf.hibernate.impl.SessionImpl.delete(SessionImpl.java:1133) at org.springframework.orm.hibernate.HibernateTemplate$14.doInHibernate( HibernateTemplate.java:295) at org.springframework.orm.hibernate.HibernateTemplate.execute(Hibernate Template.java:150) at org.springframework.orm.hibernate.HibernateTemplate.delete(HibernateT emplate.java:293) at com.cnetnetworks.service.psp.catalog.test.HibernateCatalogDaoAdminImp lTest.deleteTable(HibernateCatalogDaoAdminImplTest.java:34) at com.cnetnetworks.service.psp.catalog.test.CatalogDaoImplTest.testDele te(CatalogDaoImplTest.java:103) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl. java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces sorImpl.java:25)

35. DELETE then INSERT in collection - Order of executed SQL    forum.hibernate.org

Hibernate version: 2.1.4 A question related to updating a collection: According to the manual, this is the order of how SQL is executed: Quote: 1. all entity insertions, in the same order the corresponding objects were saved using Session.save() 2. all entity updates 3. all collection deletions 4. all collection element deletions, updates and insertions 5. all collection insertions 6. all ...

36. delete-orphan not behaving like the all-delete-orphan???    forum.hibernate.org

All I am doing is clearing out the collection. I happen to have a table of 2 items. I get the 1st item whose primary key is 1(I added it to the db myself). With the option of delete-orphan, the orphan is not deleted even though I removed the reference from the collection. Once I switch to all-delete-orphan, the below code ...

37. Hibernate3: Problems with delete("from...") query    forum.hibernate.org

Hibernate version: 3.0 I am using Hibernate 3.0 Spring. I have a simple Java bean as follows: Product.java ----------------------------------- public class Product { private int id; private String name; //getters and setters follow ... } The mapping document looks like this: Product.hbm.xml ------------------------------------ From a Test ...

38. hibernate 3 and session.delete(query)    forum.hibernate.org

session.createQuery(...).executeUpate() [sic] *should* do the trick, but personally I've had no luck with it, at least using the old query parser. YMMV with the new query parser; alternatively, you could get the connection from the session and do this with straight JDBC. (Bulk-delete is not really within the remit of ORM) HTH Satish

39. Delete order / Nullable checks on delete    forum.hibernate.org

Hibernate version: 2.1.8 I currently have the following scenario : Class A manages a list of Class B (all-delete-orphan), and Class M manages a list of Class N (all-delete-orphan). B references N (not-null). Now...if i remove an instance of B from A, it gets deleted because of the cascading. The same holds true for removing N from M. the problem comes ...

41. Hibernate way to execute delete query a select subquery    forum.hibernate.org

Hi, I wanted to execute a query which goes like this, delete from where name in (select ... from where ...) For just delete/update query, Query.executeUpdate() is available. however my query has a select subquery. Currently i have got this done by getting the connection instance and create proparedstatement and execute the same. Is there a better way, i ...

42. Deletion approach using named query    forum.hibernate.org

Hi, I have following delete query. delete from userid where useraccontno in (1,2,3,4,5); I am looking for a nice solution to implement above using named query. Parameters of this queries are the one specified in brackes (1,2,3,4,5), using "in" SQL clause. For this I am defining above query in .hbm file delete from userid where useraccontno in (:accountNo); ...

43. log4j would like to only see updates,inserts and deletes    forum.hibernate.org

Caused by: org.springframework.orm.hibernate.HibernateSystemException: a different object with the same identifier value was already associated with the session: 1165, of class: com.*****.model.businessobject.ServiceJobCrane; nested exception is net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1165, of class: com.*****.model.businessobject.ServiceJobCrane .. Caused by: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: ...

44. select after delete behavior unclear    forum.hibernate.org

Hibernate version: 3.1.3 Code between sessionFactory.openSession() and session.close(): Session hsession = HibernateUtil.openSession(); hsession.flush(); hsession.clear(); HibernateUtil.getSessionFactory().evict(T.class); t = hsession.createQuery("select t from T as t").list(); System.out.println("T: "+t.size()); Transaction tx = hsession.beginTransaction(); tx.commit(); t = hsession.createQuery("select t from T as t").list(); System.out.println("T: "+t.size()); Name and version of the database you are using: MySQL 5 Here's the output: 19:19:20,149 INFO [STDOUT] T: 1 19:19:20,149 INFO ...

45. Delete Query    forum.hibernate.org

Hi i am trying to delete record from the table. The query i am passing to createQuery is... DELETE from T_Appl_Acct_Grp_Dtl where ( group_Id = 1 and role_Code = 'HSP' and level1 = '0041' and level2 is null and level3 is null and level4 is null) OR (group_Id = 1 and role_Code = 'HSP' and level1 = '0041' and level2 = ...

46. HQL Delete Query    forum.hibernate.org

Hi, Please help me in writing HQL delete query. My entity Class is like this public class FunctionResourcePermissionData implements java.io.Serializable { // Fields private FunctionResourcePermissionId id; private CompositeResourceData resourceObject; private FunctionData function; private String permissionCode; private Date recordCreationTimestamp; private String recordCreationUserId; private Date lastUpdateTimestamp; private String lastUpdateUserId; The Id class is public class FunctionResourcePermissionId implements java.io.Serializable { // Fields private Integer ...

47. Delete using in clause    forum.hibernate.org

I want to delete all the records from a table whose ID is present in a set of values. Can I do this using Criteria queries? For more clarity, I want to implement the following query. DELETE * FROM A WHERE ID IN (a, b, c, ...) I hav all the IN parameters in a Vector. Thanks

48. Delete Query did not work on mysql4.0.12    forum.hibernate.org

Hi , I am learning hibernate and tried to execute a delete query. The system said error in my query. Please help me on what I am doing wrong. I am using hibernate 3.1 JDK 1.3 Mysql 4.0 Error message : ERROR JDBCExceptionReporter:58 - Syntax error or access violation, message from server: "You have an error in your SQL syntax. Check ...

49. DELETE query    forum.hibernate.org

50. delete query in hibernate    forum.hibernate.org

51. Problem with Delete Query    forum.hibernate.org

52. Can the WHERE clause on an UPDATE/DELETE be modified?    forum.hibernate.org

Hello, Is there a way to update the WHERE clause in an update scenario without writing the HQL UPDATE or DELETE statement from scratch? For instance on a FIND you can pass in a criteria object which will affect the WHERE clause. Can this be done (maybe in a lifecycle event like preUpdate, prePersist), can the HQL be modified in any ...

53. hibernate delete query must begin with SELECT or FROM?    forum.hibernate.org

I am migrating our app from 2.x to 3.2.5 and face problem with delete queries. I am following the migration guide and using session.createQuery(deleteQuery).updateUpdate(), but the createQuery() throws an exception that the query must start with a SELECT or FROM. At the simplest, I am trying to do a delete with no where clause expecting all to be deleted, using something ...

55. Set of UserTypes: delete with bad param count to nullSafeSet    forum.hibernate.org

Author Message cheesus Post subject: Set of UserTypes: delete with bad param count to nullSafeSet Posted: Fri Feb 22, 2008 11:01 am Newbie Joined: Tue Aug 28, 2007 12:54 pm Posts: 13 Location: Munich, Germany Hi all, I have a Set of (Composite)UserTypes that work well for reading and writing (insert), calling nullSafeSet with an insert containing three parameter ...

56. Refresh after 1-to-m related item is deleted from db    forum.hibernate.org

Hibernate version: Hibernate 3.2.6, annotations 3.3.1 and entitymanager 3.3.2 L2 Caching disabled Name and version of the database you are using: Postgres 8.2 I have two entities: Parent and child, with parent.children as a OneToMany relationship to child. A parent and all its children are read by one EntityManager and transaction (EM1). FWIW, no changes are made to the parent or ...

57. Hibernate Named Query for insert ,update and delete    forum.hibernate.org

I am able to call the named query for select of native and object queries using select... tag and I am trying to implement the Named query for insert,update and delete but failed to implement getting some sql grammer exception,can anybody help me with some sample code to implement any of these Thanks, ss

58. DELETE sql query    forum.hibernate.org

Hi I'm new to hibernate and i have a problem with DELETE SQL query for Oracle which all request going through hibernate.Previously who developed the systems has already left the company. Hence we dont have any related documentations as well. When i went through the source , i have found only a select query. where would be the delete query located ...