rspec/rules/S3364/java/rule.adoc

57 lines
1.1 KiB
Plaintext
Raw Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
Hibernate's lazy loading allows you to retrieve just the data of the current class without being forced to load all its related classes. For instance with lazy loading, you can pull up an instance of a ``++Lecture++`` ``++@Entity++`` without being forced to load all its ``++Student++``s.
But that's only if you're storing the ``++Student++``s in a collection. Store them in an array instead, and the benefits of lazy loading are no longer available.
This rule raises an issue on each array in ``++@Entity++`` classes.
=== Noncompliant code example
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Entity
public class Lecture {
@OneToMany
private Student [] attendees; // Noncompliant
// ...
}
----
=== Compliant solution
2021-04-28 16:49:39 +02:00
2022-02-04 17:28:24 +01:00
[source,java]
2021-04-28 16:49:39 +02:00
----
@Entity
public class Lecture {
@OneToMany
private List<Student> attendees;
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
Convert this array to a collection.
=== Highlighting
* primary: array name
endif::env-github,rspecator-view[]