Skip to content

Commit

Permalink
[WINDUPRULE-966] Add @GeneratedValue rule (#888)
Browse files Browse the repository at this point in the history
* [WINDUPRULE-966] Add @GeneratedValue rule

* [WINDUPRULE-966] Fix jakarta count
  • Loading branch information
jmle committed Mar 10, 2023
1 parent 4893ff6 commit c398654
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 1 deletion.
25 changes: 25 additions & 0 deletions rules/rules-reviewed/eap8/eap7/hibernate6.windup.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,31 @@
</metadata>

<rules>
<rule id="hibernate-00005">
<when>
<and>
<javaclass references="javax.persistence.GeneratedValue">
<location>ANNOTATION</location>
</javaclass>
<or>
<dependency groupId="org.hibernate" artifactId="hibernate-core" toVersion="5.6.15.Final"/>
<project>
<artifact groupId="org.hibernate" artifactId="hibernate-core" toVersion="5.6.15.Final"/>
</project>
</or>
</and>
</when>
<perform>
<hint title="Implicit name determination for sequences and tables associated with identifier generation has changed" effort="3" category-id="potential">
<message>
The way in which Hibernate determines implicit names for sequences and tables associated with identifier generation has changed in 6.0 which may affect migrating applications.
As of 6.0, Hibernate by default creates a sequence per entity hierarchy instead of a single sequence hibernate_sequence.
Due to this change, users that previously used `@GeneratedValue(strategy = GenerationStrategy.AUTO)` or simply `@GeneratedValue` (since `AUTO` is the default), need to ensure that the database now contains sequences for every entity, named `&lt;entity name&gt;_seq`. For an entity Person, a sequence person_seq is expected to exist. It’s best to run hbm2ddl (e.g. by temporarily setting `hbm2ddl.auto=create`) to obtain a list of DDL statements for the sequences.
</message>
<link href="https://github.com/hibernate/hibernate-orm/blob/6.0/migration-guide.adoc#implicit-identifier-sequence-and-table-name" title="Hibernate ORM 6 migration guide - Implicit Identifier Sequence and Table Name"/>
</hint>
</perform>
</rule>
<rule id="hibernate-00010">
<when>
<javaclass references="org.hibernate.annotations.{annotation}"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
import org.hibernate.jmx.internal.DisabledJmxServiceImpl;

import org.hibernate.criterion.Criterion;
import javax.persistence.GeneratedValue;

@NamedNativeQuery(callable = true, name = "name", query = "query")
public class HibernateOrm6TestClass implements BasicType {
@AnyMetaDef(metaType = "type")
String hey;

@GeneratedValue
@ParamDef(name = "name", type = "type")
String param;

Expand Down
Binary file not shown.
10 changes: 10 additions & 0 deletions rules/rules-reviewed/eap8/eap7/tests/hibernate6.windup.test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@
<rulePath>../</rulePath>
<ruleset>
<rules>
<rule id="hibernate6-tests-00005">
<when>
<not>
<hint-exists message="The way in which Hibernate determines implicit names for sequences and tables associated with identifier generation has changed in 6.0 which may affect migrating applications*"/>
</not>
</when>
<perform>
<fail message="[hibernate6-tests-00005] Hint not found!"/>
</perform>
</rule>
<rule id="hibernate6-tests-00010">
<when>
<not>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<rule id="javax-to-jakarta-import-00001-test">
<when>
<not>
<iterable-filter size="41">
<iterable-filter size="42">
<hint-exists message="Replace the `javax."/>
</iterable-filter>
</not>
Expand Down

0 comments on commit c398654

Please sign in to comment.