Jose_ibi wrote:
Hi, I've been over two days searching for a solution and I'm not been able to find a solution or an explanation. Maybe someone here could help me.
I want to use a ordered collection with @onetomany. Here are fragments of my entities:
Order.class
@OneToMany(cascade=CascadeType.ALL, targetEntity=OrderLine.class, mappedBy="order")
@OrderBy("date")
private List<OrderLine> orderLines = new ArrayList<OrderLine>();
OrderLine.class
@ManytoOne
Order order;
This don't work:
ArrayList<OrderLine> lines = order.getOrderLines();
When I try to get the order lines from an order, it is always returning a PersistenBag object that I can't cast to ArrayList and so it's launching a class cast exception.
I'm using Hibernat 3.6, I was using 3.5 but I updated to see if it solves the problem.
Thanks in advance.
P.S. Excuse my poor english.
Do you need the association to be bidirectional? The simplest one-way method to implement a one-to-many association is to use just @OneToMany annotation in the containing element (so "listed" objects do not need to keep a reference to the container object).
p.s I usually write annotations on getters :O