Skip to content

Instantly share code, notes, and snippets.

@jonathanvila
Created March 8, 2019 10:31
Show Gist options
  • Save jonathanvila/2604c2635eabd69870129d3a2957c8fb to your computer and use it in GitHub Desktop.
Save jonathanvila/2604c2635eabd69870129d3a2957c8fb to your computer and use it in GitHub Desktop.
Complex rule
<!--https://issues.jboss.org/browse/WINDUPRULE-385-->
<rule id="hibernate4-00040">
<when>
<and>
<!-- check if we are calling the setFirstResult method of one of the Query class -->
<javaclass references="{param_classes_setfirstresult}.setFirstResult(int)" >
<location>METHOD_CALL</location>
</javaclass>
<javaclass references="org.hibernate.dialect.{param_dialects}" as="result_classes_dialect">
<location>INHERITANCE</location>
</javaclass>
<!-- check if the dialect is one of the special ones -->
<xmlfile matches="//s:property[@name='hibernate.dialect' and windup:matches(@value, '{result_classes_dialect}')]" as="dialects_used">
<namespace prefix="s" uri="http://xmlns.jcp.org/xml/ns/persistence"/>
</xmlfile>
<not>
<!-- check if dialect class used is overriding the method to set the limit handler -->
<javaclass references="{*}getLimitHandler()" from="result_classes_dialect">
<location>METHOD</location>
</javaclass>
</not>
</and>
</when>
<perform>
<iteration over="dialects_used">
<hint title="Hibernate 4.3 - Dialects not supporting Limit Offset" effort="1" category-id="mandatory">
<message>Dialect used does not support limit offset therefore as `setFirstResult` is used then hibernate.legacy_limit_handler=true is mandatory.</message>
<link title="Red Hat JBoss EAP 7.2: Migrating from Hibernate ORM 4.3 to Hibernate ORM 5.3" href="https://access.redhat.com/documentation/en-us/red_hat_jboss_enterprise_application_platform/7.2/html-single/migration_guide/#migrating_from_hibernate_5_1_to_5_3"/>
<tag>hibernate</tag>
</hint>
</iteration>
</perform>
<where param="param_classes_setfirstresult">
<matches pattern="javax.persistence.Query|org.hibernate.Query|org.hibernate.Criteria"/>
</where>
<where param="param_dialects">
<matches pattern="Cache71Dialect|DB2390Dialect|InformixDialect|IngresDialect|RDMSOS2200Dialect|SQLServerDialect|TimesTenDialect"/>
</where>
</rule>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment