JPAContainer and Primitives


I’m trying to bind a TextField for my entity property. This property is of type int.

JPAContainer<MyClass> container = ..... ;
Item item = container.getItem(1); // get item by itemId = 1

TextField code = new TextField("Code");

When my application loads, it displays the current Code, but when I change the value in field I get this exception:
$ConversionException: Unable to convert value of type java.lang.Integer to presentation type class java.lang.String. No converter is set and the types are not compatible.

I’m using:

  • vaadin 7.0.5
  • JPAContainer 3.0.0

If I’m use the BeanItem, everything works!
I think this is a limitation/bug of JPAContainer.

I have the same issue. Would be nice to know if it’s a bug of JPAContainer.

Thanks in advance!

In the example above, it seems Vaadin hasn’t found a number to string converter for the field. This might be related to what the JPAContainer returns in this case as the field type.

More details about the field types used, exact Vaadin and JPAContainer versions used etc. might be helpful.

I’d recommend first checking what myJpaContainer.getType(problematicColumnId) returns, and then checking whether ConverterUtil.getConverter(String.class, columnTypeFromPreviousStatement, VaadinSession.getCurrentSession()) can find some converter for it.

Hi Henri

I checked the returned type value of myJpaContainer which is int and the “ConverterUtil.getConverter” method returned null (no converter avaible for it).
I’m using Vaadin 7.1 and JPAContainer 3.1.

So apparently e.g. IndexedContainer returns Integer.class as the property type (which gets a converter automatically) but JPAContainer returns int.class in this case, and there is no converter configured for it.

I haven’t tested this, but defining your own converter for int.class (following the model of StringToIntegerConverter) and using it for the field (either by setting the converter instance explicitly or by
re-configuring the ConverterFactory used
) might help.

I changed the field type of the field from int (primitve type) to Integer and checked what myJpaContainer.getType(ColumnId) returned. The result was like I expected: “java.lang.Integer” (no conversion exception). So the problem is, as you already mentioned in your previous post, within the field type “int” (int.class).

I’m going to try to use an own converter for the int.class, which is going to solve the problem eventually.

Hi Nikola did you solve your problem ? I have the same problem.