darrachequesne / spring-data-jpa-datatables

Spring Data JPA extension to work with the great jQuery plugin DataTables (https://datatables.net/)
Apache License 2.0
447 stars 173 forks source link

datatables search capability #2

Closed tomcgn closed 8 years ago

tomcgn commented 8 years ago

Hello Damien,

I am working on the search, the last missing bit. I had a look at your description here as well as at the a bit outdated one here and this one.

However, I can't get the search field to work as it should. An exception gets thrown, which isn't to revealing for me.

I added a Specification class to handle the search parameter, but no luck.

So, how could a simple search over all fields be realised? It would be great if the search worked in a generic way, on all members of type string for example.

Or can a dynamic method call such as DataTablesOutput<Meeting> findAllByTitle(DataTablesInput input, String title); be used?

Kind regards, Tom

21:28:55 ERROR (DirectJDKLog.java:182) : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.transaction.TransactionSystemException: Could not commit JPA transaction; nested exception is javax.persistence.RollbackException: Transaction marked as rollbackOnly] with root cause
javax.persistence.RollbackException: Transaction marked as rollbackOnly
    at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:74) ~[hibernate-entitymanager-4.3.6.Final.jar:4.3.6.Final]
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517) ~[spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96) ~[spring-tx-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:48) ~[metrics-spring-3.0.4.jar:na]
    at com.ryantenney.metrics.spring.TimedMethodInterceptor.invoke(TimedMethodInterceptor.java:34) ~[metrics-spring-3.0.4.jar:na]
    at com.ryantenney.metrics.spring.AbstractMetricMethodInterceptor.invoke(AbstractMetricMethodInterceptor.java:59) ~[metrics-spring-3.0.4.jar:na]
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653) ~[spring-aop-4.1.7.RELEASE.jar:4.1.7.RELEASE]
darrachequesne commented 8 years ago

That exception javax.persistence.RollbackException is indeed not really helpful.

Yes, the search feature should work, either by global search search[value] or per-column search columns[i][search][value] in the payload sent to the server (described there).

Note: the default input field on the right of the table should trigger a global search.

I'm afraid I'll need a bit more to help you:

If you don't want to/can't share this here, maybe could you contact me by mail?

Cheers!

tomcgn commented 8 years ago

Damiens Spring Data JPA datatables work great! Especially if one links jquery.spring-friendly.js properly in the containing HTML as described e.g. here :smile:

darrachequesne commented 8 years ago

Great news :smile: !

I was wondering whether your columns were @OneToMany or @ManyToMany relationships, since it involves a bit more work (the data should be something like linkedentity.attribute, see example there), but if it works for you, that's great!

diorndk commented 3 years ago

Great news 😄 !

I was wondering whether your columns were @OneToMany or @ManyToMany relationships, since it involves a bit more work (the data should be something like linkedentity.attribute, see example there), but if it works for you, that's great!

Hey Damien,

it seems the link you've given is not working now. can you provide a new link? since I'm working with @OneToMany and @ManyToMany relationship now with data table

Thanks

darrachequesne commented 3 years ago

@diorndk you are right!

The example project is here: https://github.com/darrachequesne/spring-data-jpa-datatables-sample

And the lines in question: https://github.com/darrachequesne/spring-data-jpa-datatables-sample/blob/f9a10c2d252ac0ecae978fe17f66ebcef305d82d/src/main/resources/static/index.html#L82-L85

diorndk commented 3 years ago

Hey Damien @darrachequesne,

it's work like a charm now! thanks a lot for your help!!