Hope I can help.

I have this class ItemHolder which holds Item.  I added
"@*org.hibernate.annotations.Cascade(value
= org.hibernate.annotations.CascadeType.DELETE_ORPHAN)*" to avoid orphans,
that's a Hibernate specific annotation so if you're not using Hibernate
should remove that line.


@Entity
public class ItemHolder extends BaseObject implements Serializable {
    private static final long serialVersionUID = 636111385397748769L;

    private Long id;
    private String name;
    private Set<Item> items = new TreeSet<Item>();

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    @OneToMany(cascade = { CascadeType.PERSIST, CascadeType.MERGE,
            CascadeType.REMOVE }, fetch = FetchType.EAGER, mappedBy =
"holder")
    @org.hibernate.annotations.Cascade(value =
org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
    public Set<Item> getItems() {
        return items;
    }

    // setters... compareTo, toString, ...
}

/*******************************************************************************/

@Entity
public class Item extends BaseObject implements Serializable,
        Comparable<Item> {
    private static final long serialVersionUID = -8012390283090108620L;

    private Long id;
    private String itemName;
    private ItemHolder holder;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getId() {
        return id;
    }

    public String getItemName() {
        return itemName;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "itemholder_id", nullable = false)
    public ItemHolder getHolder() {
        return holder;
    }

    // setters... compareTo, toString, ...

}

On Wed, May 20, 2009 at 10:43 AM, Mauricio Ferreyra <maur...@gmail.com>wrote:

> Hi all,
>
> I've a problem mapping objects in Hibernate. The problem is that when I
> mapped a List on a object the result is multiplied as size of array.
>
> Example:
>
> public class ClassThatContainsList{
>
> @OneToMany(mappedBy="classThatContainsLis",fetch=FetchType.EAGER,cascade={CascadeType.ALL})
>     private List<AObject> objectsList;
>
> }
>
> public class AObject{
>     @ManyToOne
>     private ClassThatContainsList classThatContainsList;
> }
>
> When I get a object of type ClassThatContainsList the result is multiplied
> as size of array.
>
> I don't want do the relation LAZY because the performance is low.
>
> What I can do?
>
>
>
>

Reply via email to