0

On the JSP page, I am doing like this ${records.size} where records is of Set type. Then I am getting this error. I check the documentation and size() method is available in org.hibernate.collection.internal.PersistentSet. So what could be possible reason for this error?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555

1 Answers1

2

The syntax ${records.size} basically tells EL to print the size property (not method!) of the bean as identified by ${records}. When EL needs to obtain a property, then it will look up the getter method in the class behind the bean. So when the property name is size then the expected getter method is getSize(). If this method is absent, then you will face exactly the exception you're currently facing. See also javax.el.PropertyNotFoundException: Property 'foo' not found on type com.example.Bean.

And indeed, the org.hibernate.collection.internal.PersistentSet does not have the getSize() method. I.e. it does indeed not have the size property at all. So the exception is completely right.

Basically you want to invoke the size() method instead, not the getter method behind the size property. Fix your EL expression accordingly:

${records.size()}
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • You are right regarding this question. Actually records is my embedded collection and to get its size on JSP using 'fn: length' I need to initialize each record. I read somewhere using @LazyCollection(LazyCollectionOption.EXTRA) you can use size() ,isEmpty() methods directly without initializing it. And it works when I call the size() method from the controller. But when I try to access size() method on JSP page it again throws an error- failed to lazily initialize a collection of role: xxx, could not initialize proxy - no Session. – ruturaj powar Dec 23 '19 at 14:41