JPAContainer calling all (even non-binded & transient) getter properties

The title says it all.

I am using hibernate and latest version of vaadin 6 and jpacontainer for vaadin 6
I am using jpacontainer to bind some entities to vaadin tables. Somehow the table or jpacontainer calls all getters, even @Transient @Entity property getters. Some of those transient getters do costly operations and want to prevent that from happening. The transient properties are not even defined in the visible collumns of the table.

I think relevant stack trace is this

    at com.desapy.s2.entity.PrintOrder.getOrderedCheckbookRequests(PrintOrder.java:218) // Property NOT used in table visible collumns.
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.vaadin.addon.jpacontainer.metadata.ClassMetadata.getPropertyValue(ClassMetadata.java:165)
at com.vaadin.addon.jpacontainer.metadata.ClassMetadata.getPropertyValue(ClassMetadata.java:340)
at com.vaadin.addon.jpacontainer.PropertyList.getPropertyValue(PropertyList.java:674)
at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.getRealValue(JPAContainerItem.java:172)
at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.getValue(JPAContainerItem.java:159)
at com.vaadin.addon.jpacontainer.JPAContainerItem$ItemProperty.toString(JPAContainerItem.java:177)
at com.vaadin.ui.Table.formatPropertyValue(Table.java:3571)
at com.vaadin.ui.Table.getPropertyValue(Table.java:3523)
at com.vaadin.ui.Table.getVisibleCellsNoCache(Table.java:1923)
at com.vaadin.ui.Table.refreshRenderedCells(Table.java:1542)
at com.vaadin.ui.Table.enableContentRefreshing(Table.java:2723)
at com.vaadin.ui.Table.setContainerDataSource(Table.java:2304) // so apparently all entities from current page receives a call in it's getter methods :(
at com.desapy.s2.ui.AdminPrintOrderView.<init>(AdminPrintOrderView.java:236)

Thanks for the quick answer :smiley:

Magically changing

@Transient List getOrderedCheckbookRequest() {
… to …
@Transient List obtainOrderedCheckbookRequest() {

fix the thing.

So it is confirmed, somehow the table component and/or jpacontainer calls to all getters unnecesarily.
Is this a bug ? It definitelly is for me, getters are NOT to be called just because …

I had a similar issue (it would detect incorrect getter methods for properties , and also detect properties that was added by the byte code weaving of the JPA implementation), It is com.vaadin.addon.jpacontainer.metadata.MetadataFactory ( and there is not simple way to override it ).

I made a copy of it (and many other classes in order to change JPAContainer to use my implementation) and made some changes.

to fix the incorrect getter methods for properties :
I changed the code that identifies the getter Method to also check for empty parameter List ( if it does not have empty parameter list , it is not the getter ).
Methods that needed change was extractPropertiesFromFields and extractPropertiesFromMethods

Was


if (m.getName().startsWith("get") && !Modifier.isStatic(mod)  && 
  !m.isSynthetic() && m.getReturnType() != Void.TYPE)  {
 ...
}

Changed to


if (m.getName().startsWith("get") && !Modifier.isStatic(mod) && 
   !m.isSynthetic() && m.getReturnType() != Void.TYPE 
   && ((m.getParameterTypes() == null) || (m.getParameterTypes().length == 0)))  {
 ...
}

to Fix the issue with incorrect properties ( I suspect this will fix your problem too although I checked the original code, they DO check for @Transient annotation …) I used the EntityManager.getMetamodel() to query the Properties as registered by the JPA implementation instead of just relying on reflection’s getDeclaredMethods and getDeclaredFields


            final javax.persistence.metamodel.Metamodel metamodel = eManager.getMetamodel();
            EntityType<T> entityType = metamodel.entity(mappedClass);
            for (Attribute<? super T, ?> attr : entityType.getAttributes()) {
                 .....
            }

My issue did not manifest itself with table though( I suspect it is because I explicitly set visible columns on my tables), only when I did embedded fields( where I did not set explicit visibly field ) did the issue rise with the incorrect property names.

I do explicitly set visible collumns too. And the getter in question was not included in that list.
Btw, you did a manual hack to fix it, but did you file a bug ?

Did not file a bug, but I did make a Forum
post
about it , to ask the Developers if there was specific reason they used Reflection instead of the EntityManager to get MetaData ( no response ) BTW this was for version 2.x.x . There might be some pitfalls I’m not aware of …

The getter method detection is independent of the above issue and I do consider this a bug. (I’ll submit a patch or bug Report for this ).

Getting MetaData from the EntityManager I consider to be a cleaner solution than reflection , but as I said there might well be pitfalls I’m not aware of so I was hoping to get a discussion going in that issue (re the post ) .

I’ll have a look at version 3. to see what they do there and do a Bug Report/ Change Request.

edit - 2013-02-05
Filed
Ticket #10936
- this will not fix your specific problem though, for that I’ll need to submit an enhancement Ticket , I first need to clean up a version of MetadataFactory that uses the EntityManager’s Metadata model to detect Properties…