Update « Collection « JPA Q&A





1. Hibernate collection handling basics    stackoverflow.com

I"m new to Hibernate. I have 3 tables: Companies, Profiles and Sites. The relation is - one company has many Profiles and Sites (one-to-many).

<hibernate-mapping>

<class name="com.bla.dataobject.CompanyData" table="companies">
 <id name="companyId" column="company_id">
 ...

2. How to force NHibernate not to update all objects in collection    stackoverflow.com

How to force NHibernate not to generate UPDATE for each element in collection if I change only one element of that collection. Here it is:

internal class Master
{
    private ...

3. Hibernate issuing updates when collection is not modified    stackoverflow.com

We have a simple parent-child relationship, to prevent calling code from modifying the relationship, we are using google collections -ImmutableSet.copyOf on get method.

    public Set<OrganizationalUnit> getChildren()
  ...

4. How do I update a collection on hibernate?    stackoverflow.com

I have the following classes:

class A {
  Integer id;

  @OneToMany(mappedBy="parent", fetch=FetchType.EAGER, cascade={CascadeType.ALL})
  Set<B>  children;
}

class B {
  Integer id;

  @ManyToOne(fetch=FetchType.EAGER)
  A parent;
}
there's data in the ...

5. Dirty checking collections - update undoes previous update    forum.hibernate.org

Fairly new at Hibernate, sorries. Weird problem, So far my logs tell me everything's working fine, and my new OrderPlaced and Invoice are committed to the database properly and the method ends. The Invoice is coupled to the OrderPlaced via: OrderPlaced.invoice_id and Invoice.orderPlaced_id. Then Hibernate suddenly comes with a: Code: 2010-02-01 16:00:35,420 DEBUG [org.hibernate.jdbc.AbstractBatcher] Executing batch size: 1 2010-02-01 16:00:35,437 DEBUG ...

6. Update collection in Hibernate    forum.hibernate.org

7. Update to main object when changing a collection    forum.hibernate.org

Hi, every time i change a collection (add/remove elements) the main object gets updated as well (version attribute). I want to disable this update as it is useless (at least i think that a change to a collection should not create a new version) and is a performance issue in the application. Does anybody know how i can disable this? Thanks! ...

8. Updating Collections    forum.hibernate.org

Can somebody explain to me how to persist additions and removals to a collection of a parent entity. I want to: 1. outside of a session, add a Person to a Phone entity's Set 2. update(phone) - and insert a record in a PersonPhone join table 3. remove the newly added Person from the Phone entity's Set 4. in a separate ...

9. Hibernate issuing updates when collection is not modified    forum.hibernate.org

Author Message iboppana Post subject: Hibernate issuing updates when collection is not modified Posted: Mon Apr 25, 2011 1:35 pm Newbie Joined: Mon Apr 25, 2011 11:29 am Posts: 1 We have a simple parent-child relationship, to prevent calling code from modifying the relationship, we are using google collections -ImmutableSet.copyOf on get method. Code: public Set getChildren() ...





10. update collection of objects using hibernateCriteria in one    forum.hibernate.org

Hi all this is the problem i encountered is there any mechanism to update a bulk of records using hibernate criteria in one go the scenario is as follows i have 10 user Objects where i need to update a field let us say xyz to true from false i.e., ineed to update one field in 10 records in one go ...

11. can't get update to work with collection    forum.hibernate.org

Hi, I did read the chapter on parent/child relationship but could not find much help. I have a parent/child relationship with a and inverse=true. I can add a parent with children like below. session.save(parent); parent.setParent(); // set parent for all children objects session.update(parent); Problem is that when I update the parent, the children are duplicated (in other words, old children ...

12. Extra update when adding item to collection issue    forum.hibernate.org

I have a parent-child relationship similar to the one in Chapter 9 of the docs except my collection belongs to a component of the parent. The relation is bidirectional and mapped with inverse=false. When I do the following Code: //parent loaded in another session Child child = new Child(); child.setParent(parent); parent.getComponent().getChildren().add(child) parent.setModified(new Date()); session.update(parent); I get the following SQL generated 1. ...

13. updating collection state    forum.hibernate.org

I have a question about collections in one to many relationship my concern is extra queries and how to avoid them in a desktop application. for example Parent has more children Parent p; child c; when I save Child and it has a parent defined after flushing Parent in my session is not updated so I update p.getChildren().add(c); does any one ...

14. avoid updating collection when updating an object    forum.hibernate.org

Newbie Joined: Thu Sep 09, 2004 7:54 pm Posts: 4 Hibernate version: 2.1.6 Mapping documents: Code: ...

15. Cannot update or add to a collection using lazy=true    forum.hibernate.org

Newbie Joined: Tue Sep 14, 2004 1:35 pm Posts: 9 Hibernate version: 2.1.4 Mapping documents: other properties.... ...

16. Why updating when adding to collection?    forum.hibernate.org

Using Hibernate version 2.1.2, I'm executing the following code: Session session = this.sessionFactory.openSession(); Transaction tx = session.beginTransaction(); theGroup = (PersistentEnumValueGroup)session.load( PersistentEnumValueGroup.class, new Integer(3) ); PersistentEnumValue theEnumValue = new PersistentEnumValue(); theEnumValue.setGroupId( theGroup.getId() ); theEnumValue.setCode( new Integer(1) ); theGroup.getEnumValues().add( theEnumValue ); theEnumValue = new PersistentEnumValue(); theEnumValue.setGroupId( theGroup.getId() ); theEnumValue.setCode( new Integer(2) ); theGroup.getEnumValues().add( theEnumValue ); session.update( theGroup ); tx.commit(); session.close(); And I get ...





17. Update of Collection support    forum.hibernate.org

Is there a way to persist a Collection of Objects in Hibernate say, [code]session.update(Collection Object as arg.)[/code] Also, is there a way to set a single property in a Collection of Objects by using PropertyAccessor and Setter and other APIs in the package net.sf.hibernate.property and then call the above single line of code and boom it persists the updated collection. Pl. ...

18. Updating collections in a 3-tier application    forum.hibernate.org

Hibernate version: 2.1.3 Hi, I am having a scenario where i retrieve a persistent object in a stateless session bean. I convert this persistent object to a domain element and pass it over to the web-tier. The persistent object has a one-to-many relationship with one more persistent object, as below: class A { Object id; .... java.util.Set childObjects; } class B ...

19. Cannot update members of a collection    forum.hibernate.org

Read the rules before posting! http://www.hibernate.org/ForumMailingli ... AskForHelp Hibernate version: 2.1 Mapping documents: Code between sessionFactory.openSession() and session.close(): Session sess = null; try { sess = PsaDAO.getHibernateSession(); Transaction t = sess.beginTransaction(); //order number is going to be based on the call date Iterator callsItr = calls.iterator(); while (callsItr.hasNext()) { i++; //for each call in the call list CallCycleGridCellVO cellVO = (CallCycleGridCellVO) ...

20. Update a tranisent object that containts a collection wo PKs    forum.hibernate.org

Hi, I am trying to figure out how to update a chain of objects without knowing their PK. Lets say I have two tables (and objects) County and State. State contains counties (parent-child assoc). Both tables use a surrogate key for PK but they both have unique constraints. In the application I want to update the tables using data from a ...

21. Lazy collection not being fetched after update    forum.hibernate.org

Beginner Joined: Tue Nov 09, 2004 9:48 am Posts: 23 Read the rules before posting! http://www.hibernate.org/ForumMailingli ... AskForHelp Hibernate version: 2.1.8 Mapping documents: Code:

22. Updating Object with collection    forum.hibernate.org

Hi, I have 2 POJO classes, Group and Customer. Group contains a collection of Customer objects. When I'm going to update a Group object, I can see following in the logs; Code: Hibernate: delete from customer_group where GroupId=? Hibernate: insert into customer_group (GroupId, CustomerId) values (?, ?) Hibernate: insert into customer_group (GroupId, CustomerId) values (?, ?) customer_group table is the join ...

23. Hibernate - Having trouble updating a Collection    forum.hibernate.org

Hi I'm having trouble, please help. I have a document object that contains a Set of Note Objects (a one to many relationship). Each object refers to the relevant table. However, when I edit the document object and add a new Note to the collection and try to update my changes, I get the following exception: Hibernate Exceptionobject references an unsaved ...

24. Ways of handling updates on collections when using DTOs    forum.hibernate.org

Has anyone ever found a good way of handling updates between DTOs and DOs when you have collections involved that does not lead to the issue of having two objects with the same identifier in a session. The only sollution I could find is to issue a retainAll on the collection passing the list of DOs converted from the DTOs and ...

25. collection not updated    forum.hibernate.org

Hi Guys : I have a hibernate issue which should be fairly common. I have a class ... Airplane, with a collection of seats class Airplane { Set seats; //getters and setters. } Now, when I modify one of the seats(call it s) , and I call session.refresh(s), the airplanes's list of seats does not reflect this modification. After restarting my ...

27. collection updating strategy    forum.hibernate.org

Hibernate version: 8.1.3 Hi all, I've got a situation where I need to retrieve a list of persistent objects (which happen to use a composite primary key), remove some elements, update others, change unique/primary keys and then save it. I'd to have all inserts, updates and deletes within the scope of a transaction. so basically 1. begin transaction 2. return list ...

28. Efficient way to update a collection?    forum.hibernate.org

I have never been able to figure out an efficient way to deal with updates to a collection. As an example, I have a user that has a set of emails. USERS is a database table itself containing a username and password. There is another database table EMAILS that contains an email address and a foreign key USER_ID referencing the primary ...

29. Why does the Hibernate update a not changed collection?    forum.hibernate.org

I have a list of employees (1560 to be exact). I iterate through the list of Employees in my web-application and then in the log fiel I see that Hibernate issues UPDATE statements to database on Employees! But the epmloyees did not change - I was just reading the collection and outputing the values to a web-page Do I understand smth ...

30. Additional Updates Fired While Using Indexed Collections    forum.hibernate.org

Hi, We are using: Hibernate: 3.0 MySQL: 5.0.27 JBoss: 4.0.5 Java: J2SDK 1.4.2_08 We are facing a Database performance issue while implementing bidirectional mapping between two classes (LogRecordCache and LogRecord with relation: A LogRecordCache can have a List of LogRecords). Their hibernate mappings are as shown below: 1. ------ Mapping for LogRecordCache ----- Code: ...

31. Updated: now DataException:could not initialize a collection    forum.hibernate.org

Hi all, I upgraded my jars: hibernate 3.2 to hibernate 3.2.6 entitymanager 3.3.1 to entity manager 3.3.2 I am running with a Derby back end. Everything was running perfectly in the previous version. Now I get the following exception: javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not initialize a collection: [com.emc.imf.core.model.Privilege.roles#component[componentuid,privilegekey]{componentuid=5, privilegekey=PrivilegeKey4}] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74) at com.emc.imf.core.model.DbObjRetriever.getVAApps(DbObjRetriever.java:34) at com.emc.imf.core.model.BOMFacadeManager.getVAApps(BOMFacadeManager.java:463) at com.emc.imf.core.model.TestBOMComponents.getVAApps(TestBOMComponents.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ...

32. Updated: now DataException:could not initialize a collection    forum.hibernate.org

Hi all, I upgraded my jars: hibernate 3.2 to hibernate 3.2.6 entitymanager 3.3.1 to entity manager 3.3.2 I am running with a Derby back end. Everything was running perfectly in the previous version. Now I get the following exception: javax.persistence.PersistenceException: org.hibernate.exception.DataException: could not initialize a collection: [com.emc.imf.core.model.Privilege.roles#component[componentuid,privilegekey]{componentuid=5, privilegekey=PrivilegeKey4}] at org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:637) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:74) at com.emc.imf.core.model.DbObjRetriever.getVAApps(DbObjRetriever.java:34) at com.emc.imf.core.model.BOMFacadeManager.getVAApps(BOMFacadeManager.java:463) at com.emc.imf.core.model.TestBOMComponents.getVAApps(TestBOMComponents.java:65) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ...

33. Update collection listener while updating collection's entit    forum.hibernate.org

Hibernate version: 3.2.6 Hi, I'm using the interface PostCollectionUpdateEventListener to log changes in object's collection. The listener is invoked when I add or remove an entity from the collection. The listener is not being invoked while I'm updating an entity in the collection. The listener that is being invoked here is PostUpdateEventListener, while I expected from the collection listener (PostCollectionUpdateEventListener) to ...

34. Partial updates with collections    forum.hibernate.org

Hi, I am thinking of doing the following but am not sure if it is a good idea because of collections. Currently I have a JSF page which is created in HTTP request scope. When a data object is retrieved from Hibernate and used to set values on this page, only some of the data object's values may be used. Then, ...