You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@cayenne.apache.org by Tomas Stenlund <to...@telia.com> on 2012/07/12 07:46:13 UTC

ToManyList cannot be instantiated with a list.getClass().newInstance()

Hi,

I'm using Cayenne 3.1B1 and Pivot 2.0.2 as a GUI and have come across 
something which I would gladly have some good suggestions around.

The automatically generated getters for the relationships sometimes 
returns a ToManyList of objects. To be able to use that list directly in 
Pivot:s widgets I have to wrap it with a ListAdapter. So, now for the 
cayenne questions, it seems that ToManyList does not have an empty 
constructor (maybe it does not have one because it does not really mean 
anything in the ToMany relationship) causing a call to the 
list.getClass().newInstance() that the ListAdapter in pivot does to 
create a new empty list of the same type to throw the 
InstantiationException.

It might be that the ListAdapter is wrongly implemented to assume that 
the List:s always have an empty constructor or something else. Any ideas 
? For now I just create a new list (ArrayList or something similar) and 
fills it up with the objects in the ToManyList to send it into Pivot to 
make it work, but it does seem to give an ugly solution moving from one 
list type to another just to come around this.

Thanks for any comments,

Cheers,

Tomas

Re: ToManyList cannot be instantiated with a list.getClass().newInstance()

Posted by Andrus Adamchik <an...@objectstyle.org>.
Hi Tomas,

> PS ! Have a look at the application at http://blog.stenlund.cc/?page_id=26, a cross country skiing time recording and competition management application using Apache Pivot and Cayenne. It is a pleasure working with those two frameworks, among other. DS!


Nice! :)

Andrus

On Jul 26, 2012, at 10:31 AM, Tomas Stenlund wrote:

> Hi Andrus,
> 
> thanks for taking your time to give your opinion.
> 
> Yes, I have come to the same conclusion as you. The TooMany list outside cayenne don't really mean anything. Since Pivot is able to swallow List:s right out of the box to display them in List-, Tablewiddgets etc. I got led down the wrong alley. Looking into the source of Pivot it actually does some manipulating with the List and creation of new Lists that will not work with cayenne. I have also discussed this with the guys at the Pivot  list.
> 
> So, now I convert the Cayenne TooManyList to simple "Java lists" and send them into Pivot instead. So when the Pivot dialogues want to change some data in the CayenneObjects it goes through getters/setters I can just then commit the changes after the user for instance press "Save". So it works well.
> 
> Cheers,
> 
> Tomas
> 
> PS ! Have a look at the application at http://blog.stenlund.cc/?page_id=26, a cross country skiing time recording and competition management application using Apache Pivot and Cayenne. It is a pleasure working with those two frameworks, among other. DS!
> 
> On 07/23/2012 03:39 PM, Andrus Adamchik wrote:
>> Not familiar with Pivot, so not sure what its expectations are. But creating a ToManyList outside Cayenne generally doesn't seem like a good idea. Maybe what you doing as a workaround is perfectly valid. So what is the purpose of creating a new list by Pivot and what happens to that list after that? Is there an attempt to persist it afterwords?
>> 
>> Cheers,
>> Andrus
>> 
>> 
>> On Jul 12, 2012, at 8:46 AM, Tomas Stenlund wrote:
>> 
>>> Hi,
>>> 
>>> I'm using Cayenne 3.1B1 and Pivot 2.0.2 as a GUI and have come across something which I would gladly have some good suggestions around.
>>> 
>>> The automatically generated getters for the relationships sometimes returns a ToManyList of objects. To be able to use that list directly in Pivot:s widgets I have to wrap it with a ListAdapter. So, now for the cayenne questions, it seems that ToManyList does not have an empty constructor (maybe it does not have one because it does not really mean anything in the ToMany relationship) causing a call to the list.getClass().newInstance() that the ListAdapter in pivot does to create a new empty list of the same type to throw the InstantiationException.
>>> 
>>> It might be that the ListAdapter is wrongly implemented to assume that the List:s always have an empty constructor or something else. Any ideas ? For now I just create a new list (ArrayList or something similar) and fills it up with the objects in the ToManyList to send it into Pivot to make it work, but it does seem to give an ugly solution moving from one list type to another just to come around this.
>>> 
>>> Thanks for any comments,
>>> 
>>> Cheers,
>>> 
>>> Tomas
>>> 
>> 
> 


Re: ToManyList cannot be instantiated with a list.getClass().newInstance()

Posted by Tomas Stenlund <to...@telia.com>.
Hi Andrus,

thanks for taking your time to give your opinion.

Yes, I have come to the same conclusion as you. The TooMany list outside 
cayenne don't really mean anything. Since Pivot is able to swallow 
List:s right out of the box to display them in List-, Tablewiddgets etc. 
I got led down the wrong alley. Looking into the source of Pivot it 
actually does some manipulating with the List and creation of new Lists 
that will not work with cayenne. I have also discussed this with the 
guys at the Pivot  list.

So, now I convert the Cayenne TooManyList to simple "Java lists" and 
send them into Pivot instead. So when the Pivot dialogues want to change 
some data in the CayenneObjects it goes through getters/setters I can 
just then commit the changes after the user for instance press "Save". 
So it works well.

Cheers,

Tomas

PS ! Have a look at the application at 
http://blog.stenlund.cc/?page_id=26, a cross country skiing time 
recording and competition management application using Apache Pivot and 
Cayenne. It is a pleasure working with those two frameworks, among 
other. DS!

On 07/23/2012 03:39 PM, Andrus Adamchik wrote:
> Not familiar with Pivot, so not sure what its expectations are. But creating a ToManyList outside Cayenne generally doesn't seem like a good idea. Maybe what you doing as a workaround is perfectly valid. So what is the purpose of creating a new list by Pivot and what happens to that list after that? Is there an attempt to persist it afterwords?
>
> Cheers,
> Andrus
>
>
> On Jul 12, 2012, at 8:46 AM, Tomas Stenlund wrote:
>
>> Hi,
>>
>> I'm using Cayenne 3.1B1 and Pivot 2.0.2 as a GUI and have come across something which I would gladly have some good suggestions around.
>>
>> The automatically generated getters for the relationships sometimes returns a ToManyList of objects. To be able to use that list directly in Pivot:s widgets I have to wrap it with a ListAdapter. So, now for the cayenne questions, it seems that ToManyList does not have an empty constructor (maybe it does not have one because it does not really mean anything in the ToMany relationship) causing a call to the list.getClass().newInstance() that the ListAdapter in pivot does to create a new empty list of the same type to throw the InstantiationException.
>>
>> It might be that the ListAdapter is wrongly implemented to assume that the List:s always have an empty constructor or something else. Any ideas ? For now I just create a new list (ArrayList or something similar) and fills it up with the objects in the ToManyList to send it into Pivot to make it work, but it does seem to give an ugly solution moving from one list type to another just to come around this.
>>
>> Thanks for any comments,
>>
>> Cheers,
>>
>> Tomas
>>
>


Re: ToManyList cannot be instantiated with a list.getClass().newInstance()

Posted by Andrus Adamchik <an...@objectstyle.org>.
Not familiar with Pivot, so not sure what its expectations are. But creating a ToManyList outside Cayenne generally doesn't seem like a good idea. Maybe what you doing as a workaround is perfectly valid. So what is the purpose of creating a new list by Pivot and what happens to that list after that? Is there an attempt to persist it afterwords? 

Cheers,
Andrus


On Jul 12, 2012, at 8:46 AM, Tomas Stenlund wrote:

> Hi,
> 
> I'm using Cayenne 3.1B1 and Pivot 2.0.2 as a GUI and have come across something which I would gladly have some good suggestions around.
> 
> The automatically generated getters for the relationships sometimes returns a ToManyList of objects. To be able to use that list directly in Pivot:s widgets I have to wrap it with a ListAdapter. So, now for the cayenne questions, it seems that ToManyList does not have an empty constructor (maybe it does not have one because it does not really mean anything in the ToMany relationship) causing a call to the list.getClass().newInstance() that the ListAdapter in pivot does to create a new empty list of the same type to throw the InstantiationException.
> 
> It might be that the ListAdapter is wrongly implemented to assume that the List:s always have an empty constructor or something else. Any ideas ? For now I just create a new list (ArrayList or something similar) and fills it up with the objects in the ToManyList to send it into Pivot to make it work, but it does seem to give an ugly solution moving from one list type to another just to come around this.
> 
> Thanks for any comments,
> 
> Cheers,
> 
> Tomas
>