Did you ever find a solution to this? I have a ManyToMany relation that's getting the same error, although the class in question is not abstract at all.
In my main entity, I have the relation defined as:
Code:
@ManyToMany(cascade = CascadeType.ALL)
private Set<ArtCategoryPrice> prices = new HashSet<ArtCategoryPrice>();
The ArtCategoryPrice entity is super-simple:
Code:
package com.gradient.art.domain;
import org.springframework.roo.addon.javabean.RooJavaBean;
import org.springframework.roo.addon.jpa.activerecord.RooJpaActiveRecord;
import org.springframework.roo.addon.json.RooJson;
import org.springframework.roo.addon.tostring.RooToString;
@RooJavaBean
@RooToString
@RooJson
@RooJpaActiveRecord
public class ArtCategoryPrice {
private float amount;
}
Single field, no reverse relationship at all. I thought of adding a custom converter, but the generated ApplicationConversionServiceFactoryBean class now shows the installFormatters() method as deprecated, and I haven't found anything that instructs how to replace it.
I am curious to see how you managed to get around the problem. Perhaps I might just start a dummy project and see what gets generated, or just add the custom converter the old way and worry about the deprecation at a later time.
Update:
I added a custom converter as mentioned above as such:
Code:
public Converter<Set<ArtCategoryPrice>, String> getSetOfArtCategoryPriceToStringConverter() {
return new Converter<Set<ArtCategoryPrice>, String>() {
@Override
public String convert(Set<ArtCategoryPrice> source) {
StringBuilder strBldr = new StringBuilder();
for(ArtCategoryPrice price : source) {
if(strBldr.length()>0)
strBldr.append(",");
strBldr.append(price.getAmount());
}
return strBldr.toString();
}
};
}
However, now I am getting this strange exception:
Code:
Caused by: java.lang.ClassCastException: com.gradient.art.domain.ArtCategory cannot be cast to com.gradient.art.domain.ArtCategoryPrice
at com.gradient.art.web.ApplicationConversionServiceFactoryBean$1.convert(ApplicationConversionServiceFactoryBean.java:30)
at com.gradient.art.web.ApplicationConversionServiceFactoryBean$1.convert(ApplicationConversionServiceFactoryBean.java:1)
at org.springframework.core.convert.support.GenericConversionService$ConverterAdapter.convert(GenericConversionService.java:517)
at org.springframework.core.convert.support.ConversionUtils.invokeConverter(ConversionUtils.java:35)
... 153 more
Why would it even try to convert a Set<ArtCategory> using a converter for Set<ArtCategoryPrice>? It appears Spring is trying to "best-fit" a conversion from another member of my ArtCategory entity:
Code:
@ManyToMany(cascade = CascadeType.ALL, fetch=FetchType.LAZY)
private Set<com.gradient.art.domain.ArtCategory> childCategories = new HashSet<com.gradient.art.domain.ArtCategory>();
So, I guess I will continue down the rabbit hole, making converters for each item that Spring is complaining about.
Update 2:
Even after adding the following:
Code:
public Converter<Set<ArtCategory>, String> getSetOfArtCategoryToStringConverter() {
return new Converter<Set<ArtCategory>, String>() {
@Override
public String convert(Set<ArtCategory> source) {
StringBuilder strBldr = new StringBuilder();
for(ArtCategory category : source) {
if(strBldr.length()>0)
strBldr.append(",");
strBldr.append(category.getName());
}
return strBldr.toString();
}
};
I am getting the exact same error as mentioned in the first update. Not sure why Spring would be trying to use a converter typed to handle Set<ArtCategoryPrice> for a Set<ArtCategory>. This is forcing me to write some very ugly code in the first converter.