if i guess correctly, you are trying to do a reverse onetomany.

After a lot of mistakes, i reached this solution for that:

@Entity
@Table (name="M_INVOICE")
public class Invoice {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name="ID_INVOICE", nullable=false)
    private Long invoiceID;

    @OneToMany(fetch=FetchType.LAZY,mappedBy="invoice",orphanRemoval=true,
cascade={CascadeType.ALL})
*    @Column(name="ID_INVOICE") // means: this is a "reverse=true"
OneToMany (same as you can declare in a Hibernate HBM file)
*    private List<InvoiceDetail> dettagli;
}

i think you miss the part in bold, which make the list really a REVERSE
oneToMany.
here the InvoiceDetail:

@Entity
@Table (name="M_INVOICE_DETAIL")
@IdClass(InvoiceDetailPK.class)
public class InvoiceDetail implements Serializable {


    @Id
    private Integer detailID;
    @Id
    private Invoice invoice;

    .....

}

and the PKClass:

public class InvoiceDetailPK implements Serializable {


    @ManyToOne(fetch=FetchType.LAZY)
    @JoinColumn(name="ID_INVOICE")
    private Fattura invoice;

    @Column(name="ID_DETAIL", nullable=false,insertable= true,
updatable=true)
    private Integer detailID;

   .....

}

and remember,* EQUALS and HASHCODE only on PK fields*.

With this solution, you can save the entity and the list associated even if
they where not previously in session.

Finally, instead of *persist* i use *save* or *merge*. (I use spring
HibernateTemplate, never used Session directly)

Hope this can help,
Giulio




2012/3/22 George Christman <gchrist...@cardaddy.com>

> Hi Giulio,
>
> Yes, that is what I'm looking for. The only reason I can't commit it at
> this
> point is due to validation exceptions. My root entity does have many others
> related.
>
> here's a snippet of my root entity.
>
> @Entity
> public class PurchaseRequest {
>
>    @Id
>    @GeneratedValue
>    @NonVisual
>    private Long id;
>
>    @Transient
>    private long tempId = UUID.randomUUID().getLeastSignificantBits();
>
>    @OneToMany(mappedBy = "purchaseRequest", cascade=CascadeType.ALL,
> orphanRemoval=true)
>    private List<LineItem> lineItems;
>
> and some of my page code.
>
> private PurchaseRequest pr;
>
> @Inject //hibernate session
> private Session session;
>
> Class<?> onActivate(PurchaseRequest pr) {
>    this.pr = pr;
> }
>
> void onValidate() {
>        if (form.getHasErrors()) {
>            session.persist(pr);
>        }
> }
>
> --
> View this message in context:
> http://tapestry.1045711.n5.nabble.com/Tapestry-Hibernate-session-reattach-tp5584040p5586326.html
> Sent from the Tapestry - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> For additional commands, e-mail: users-h...@tapestry.apache.org
>
>

Reply via email to