-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: help! newbie here.. @onetomany with arraylist
PostPosted: Fri Jan 14, 2011 5:44 am 
Newbie

Joined: Fri Jan 14, 2011 4:52 am
Posts: 1
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.


Top
 Profile  
 
 Post subject: Re: help! newbie here.. @onetomany with arraylist
PostPosted: Fri Jan 14, 2011 9:39 am 
Newbie

Joined: Thu Jan 13, 2011 3:55 pm
Posts: 4
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.