persist « Collection « JPA Q&A





1. How to have 2 collections of the same type in JPA?    stackoverflow.com

I've got 2 entities in JPA: Entry and Comment. Entry contains two collections of Comment objects.

@Entity
public class Entry {
    ...

    @OneToMany(fetch = FetchType.EAGER, cascade = ...

2. Persist collection of interface using Hibernate    stackoverflow.com

I want to persist my litte zoo with Hibernate:

@Entity
@Table(name = "zoo") 
public class Zoo {
    @OneToMany
    private Set<Animal> animals = new HashSet<Animal>();
}

// Just a marker ...

3. How to persist a collection of interface's Collection in JPA?    stackoverflow.com

I have an the following scenario:

// several classes that implement different interfaces 
class A implements X,Y {}
class B implements Y,Z {}
class C implements X,Z {}

// other classes that contain collections of ...

4. JPA/Hibernate + get specific item from onetomayrelation    stackoverflow.com

I want to get a specific row in a OneToMany relation. E.g. getting the cheapest item of an order Example:

public class Order {

 @Id
 @Column(name = "ORDER_ID")
 private Long id;

 ???
 ...

5. Stop Hibernate from updating collections when they have not changed    stackoverflow.com

I have two entity beans defined as follows (unrelated stuff removed):

@Entity
@Table(...)
public class MasterItem implements java.io.Serializable {

  private Set<CriticalItems> criticalItemses = new HashSet<CriticalItems>(0);

  @OneToMany(fetch = FetchType.EAGER, mappedBy = "masterItem", orphanRemoval ...

6. Hibernate prepersist drops collection    stackoverflow.com

@Prepersist seems to have some very strange behaviour, hibernate removes my collection before it is invoked, then adds everything again afterwards. Is this the way hibernate is working or do I ...

7. How to make collection items persistent?    forum.hibernate.org

Hello all, I am extremely new to Hibernate. I have a many-to-many relationship called PersonAddressLink between Person and Address entities as follows: Person(person_id, other attributes) ---PersonAddressLink(person_id,address_id)-----Address(address_id, other attributes) I was able to successfully map this relationship using Hibernate in two persistent classes Person and Address. In Person, I have addresses List to store all the associated address of a Person. I ...

8. persist and detach for lazy collections    forum.hibernate.org

I have a question concerning the lazy fetch function in Hibernate JPA. My test structure is quite simple: a company object which has products. Those products shall be fetched lazily. Now what happens is that after a persist and an immediate find on the EntityManager a company object is returned which does not have a products proxy (products is simply null). ...

9. Customized persistence of collection    forum.hibernate.org





11. Wrapped collection in persistent object    forum.hibernate.org

Hi! I have following case: Persistent object A contains property (lets name it 'prop') which is of class that implements Set, but actually it is a wrapper. How should I map it? I cannot use direct collection mapping, because hibernate proxy will not do what my wrapper does (hibernate proxy should be wrapped by my wrapper). Should I use CustomType or ...

12. Persist partial collections based on condition in hibernate    forum.hibernate.org

Hi All, Is it possible to persist an object using hibernate mappings, only if certain condition on the object property is true and the condition is specified in hibernate config? This requirement comes from persisting partial entries of a collection using hibernate. I have the following example. Lets say we have Event Object that has reference to collection of EventTypes. class ...

13. Wrapping a collection with a non-persistent object: how?    forum.hibernate.org

Hello, I'm stumped because I don't really know how to translate this in Hibernate terminology: I have classes A 1--1 B. The database has tables of the form A 1---* C. The B class has to load all its C records (which have a foreign key to A), but it is not itself a persistent class. I can add the C ...

14. Transparent persistence and lazy collections    forum.hibernate.org

I think I'm missing something about Hibernate's goal of transparent persistence and lazy collections. With the exception of lazy collections, I can persist any Entity with no specific Hibernate code in the POJO. This is especially true with an IoC framework like Spring. But as soon as I have a lazy collection, I need Hibernate specific code. A sample is below ...

15. Optimizing the persistence of a collection of objects    forum.hibernate.org

Greetings! forgive me if this has been posted before or if i am being naive. to start, i am using Hibernate 2.1.2 and Oracle9i. i have a program that creates and inserts a large collection of objects during a single transaction. Each persisted object includes a bi-directional relationship with another object that is also persisted. For example: Classes: Code: public class ...

16. Optimizing the persistence of collections    forum.hibernate.org

Greetings! i posted this previously in the newbie forum but thought it would be more appropriate here. i am using Hibernate 2.1.2 and Oracle9i. i have a program that creates and inserts a large collection of objects during a single transaction. Each persisted object includes a bi-directional relationship with another object that is also persisted. This relationship breaks hibernate's ability to ...





17. Persistent collection in non persistent class    forum.hibernate.org

19. Optimizing the persistence of collections    forum.hibernate.org

20. removing persistent/non-persistent items from collection    forum.hibernate.org

Hi, I'm currently removing persistent objects (child objects already saved to DB) from collections like this (simplified code version): Parent parent = (Parent) parentDAO.getObject(Parent.class, new Long(1)); Child child = (Child) childDAO.getObject(Child.class, new Long(request.getParameter("childId"))); parent.getChildren().remove(child); parentDAO.saveObject(parent); ... which works. My first question is, is there anyway to remove an already persistent object from a Set without pulling out an instance of it ...

21. persisting collection example    forum.hibernate.org

22. Iterate with filter on persistent collection error on hb 3.1    forum.hibernate.org

Need help with Hibernate? Read this first: http://www.hibernate.org/ForumMailingli ... AskForHelp Hibernate version: Hibernate 3.1 Mapping documents: PetOwner Code: ...

23. Persistent collections usage    forum.hibernate.org

Greetings, I wonder if it is possible to create instance of PersistentCollection subtype based on regular collection of persistent entities. For example in my case (webapp, hibernate behind stateless session beans) I do criteria.list() -> send results to UI -> user adds/deletes/updates the list -> then I need to store changes. At the moment there is a considerable amount of [not ...

24. Unexpected behavior when updating persistent collection...    forum.hibernate.org

I am currently using Hibernate-Version: 3.0.5 in a project that makes heavy use of the Interceptor to generate events related the creation and modification of our business objects. It's my understanding that modfications made to the contents of a persistent collection are viewed from a life-cycle perspective as modifications to the object that owns the collection. So if I add to, ...

25. Persisting a Collection in Hibernate    forum.hibernate.org

In Hibernate to update, we set the values in the POJO classes and then do Session.save(POJO); However, say we have to update a collection of these POJO's. To be more clear, I have in my jsp, rows of data which I have to update. How do I update these rows in one shot. Else, I have to have a for loop ...

26. Persisting static collection    forum.hibernate.org

27. Persist elements of 2 different collections in the same tabl    forum.hibernate.org

(using Hibernate 3.x) Person and Building have multiple Addresses. Person and Building are persisted in their own table. They do not share anything in common (separate class hierarchies). I'd like to persist the Addresses in a single table, whether they are attached to a Person or a Building. Code: public class Person { ... Collection

addresses; ...

28. many-to-many collection changes not persisting    forum.hibernate.org

29. Persistence for "interface-based collections"?    forum.hibernate.org

Hi, I have some troubles persisting an existing code base with Hibernate. I've tried to search the online resources but without any luck. I'm not sure whether my question is too simple or too special at all. Few of my classes contain some "collection of interfaces". The target entities of relations are not classes, but java interfaces like this: private Collection ...

30. Persisting a collection of objects    forum.hibernate.org

Hello, I have a collection of objects that I need to persist. Each object may be in a different state - ie .some new, some updated and need to be persisted and some that need to be deleted. This collection is not part of another object. Is there a recommended way to do this in Hibernate? I can add my own ...

31. How to proxy a persistent collection ?    forum.hibernate.org

32. Not Persist Collection?    forum.hibernate.org

i am new to hibernate, maybe this question is just silly. But please help. I have a collection in hibernate mapping file, can i just choose to use it when query the database, but not update the database? i.e. make this collection not persist to the database? I know if that is a property i can use update=false insert=false, but how ...