rspec/rules/S3356/java/rule.adoc

52 lines
1.3 KiB
Plaintext
Raw Permalink Normal View History

== Why is this an issue?
2021-04-28 16:49:39 +02:00
The ability to map a class to a database table has made database interaction in Java a lot easier. But map multiple classes to the same table and you'll end up with a classic case of the left hand not knowing what the right hand is doing. In the worse case scenario, it could lead to serious data corruption.
This rule raises an issue when multiple classes are mapped to the same table with Hibernate or JPA annotations.
=== 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 // implicitly mapped to "point" table
public class Point {
// ..
}
@Entity
@Table(name = "point") // Noncompliant
public class Spot {
// ...
}
----
ifdef::env-github,rspecator-view[]
'''
== Implementation Specification
(visible only on this page)
=== Message
"tableName" is also associated with "classname".
=== Highlighting
* primary: table name on second class
'''
== Comments And Links
(visible only on this page)
=== on 6 Oct 2015, 15:49:45 Ann Campbell wrote:
\[~nicolas.peru] I don't know if this would go in 'implementation details' but this rule should look at both classes and XML configuration files. In Hibernate, at least, you can map classes to tables in XML.
Also, since this is a cross-file check, I understand that we won't get to even the first half of it soon. :)
endif::env-github,rspecator-view[]