Inspections

Hibero adds over 60 code inspections and quick fixes. You'll find these inspections in File | Settings | Errors under the categories Hibernate issues (Hibero) and EJB3 Persistence issues (Hibero).

A description of each inspection follows:

Hibernate issues (Hibero)

  • Field Not Found
    Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one, one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array, primitive-array or nested-composite-element tags, declared in a Hibernate mapping file, with access of type field, but no field is found with such name in the corresponding class.

    Field Not Found Example

  • Final Persistent Class
    Reports any persistent final class, declared in a Hibernate mapping file, unless lazy fetching is completely disabled or a proxy interface is explicitly specified.

    Final Persistent Class Example

  • Getter Method Not Found
    Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one, one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array, primitive-array or nested-composite-element tags, declared in a Hibernate mapping file, with access of type property, but no getter method is found with such name in the corresponding class.

    Getter Not Found Example

  • Missing Identifier Type
    Reports any identifier property, declared in a Hibernate mapping file, which doesn't explicitly specifies the identifier type in the case that the name attribute is missing.

    Missing Identifier Type Example

  • Missing @CollectionOfElements Target Element
    Reports any @CollectionOfElements annotation which does not specify a target element and it cannot be inferred from the annotated field or property type (i.e., Java generics are not used for collections).

    Missing @CollectionOfElements target element Example

  • Persistent Class Name Differs From Mapping File Name
    Reports any persistent class names which do not match the name of their containing Hibernate mapping file. Although this isn't required by Hibernate, it is a convention to give the file the same name as the persistent class, with the extension '.hbm.xml'.

    Persistent Class Name Differs From Mapping File Name Example

  • Persistent Class Without No-Arg Constructor
    Reports any persistent class, declared in a Hibernate mapping file, which doesn't provide a default no-argument constructor, unless a proxy interface is explicitly specified.

    Persistent Class Without No Arg Constructor Example

  • Persistent Class With Private No-Arg Constructor
    Reports any persistent class, declared in a Hibernate mapping file, which provides a default no-argument constructor with private access, unless lazy fetching is completely disabled or a proxy interface is explicitly specified.

    Persistent Class With Private No Arg Constructor Example

  • Proxy Must Be Interface Or Class Itself
    Reports any proxy attribute, declared in a Hibernate mapping file, which isn't an interface or the persistent class itself.

    Proxy Must Be Interface Or Class Itself Example

  • Recomended Serializable Persistent Class
    Reports any persistent class, declared in a Hibernate mapping file, that doesn't implement java.io.Serializable interface. Although Hibernate doesn't require this, serialization would be necessary when objects are stored in an HttpSession or passed by value using RMI.

    Recomended Serializable Persistent Class Example

  • Required Comparator Implementor
    Reports any sort attribute, declared in a Hibernate mapping file, which references a class that doesn't implement java.util.Comparator interface.

    Required Comparator Implementor Example

  • Required EntityPersister Implementor
    Reports any persister attribute, declared in a Hibernate mapping file, which references a class that doesn't implement org.hibernate.persister.entity.EntityPersister interface.

    Required EntityPersister Implementor Example

  • Required IdentifierGenerator Implementor
    Reports any generator attribute, declared in a Hibernate mapping file, which references a class that doesn't implement org.hibernate.id.IdentifierGenerator interface.

    Required IdentifierGenerator Implementor Example

  • Required Overriden Equals HashCode
    Reports any persistent class, composite-id class, composiste-element class, or composite-map-key, declared in a Hibernate mapping file, that doesn't override equals() and hashCode().

    Required Overriden Equals HashCode Example

  • Required PropertyAccessor Implementor
    Reports any access attribute, declared in a Hibernate mapping file, which references a class that doesn't implement org.hibernate.property.PropertyAccessor interface.

    Required PropertyAccessor Implementor Example

  • Required Proxy Interface Implementor
    Reports any persistent class, declared in a Hibernate mapping file, which references a class that doesn't implement the interface specified by the proxy attribute (if any).

    Required Proxy Interface Implementor Example

  • Required Serializable Implementor
    Reports any class referenced by a composite identifier, declared in a Hibernate mapping file, that doesn't implement java.io.Serializable interface.

    Required Serializable Implementor Example

  • Required UserCollectionType Implementor
    Reports any collection-type attribute, declared in a Hibernate mapping file, which references a class that doesn't implement org.hibernate.usertype.UserCollectionType interface.

    Required UserCollectionType Implementor Example

  • Setter Method Not Found
    Reports any name attribute of id, composite-id, version, timestamp, property, key-property, many-to-one, one-to-one, component, key-many-to-one, any, map, set, list, bag, idbag, array, primitive-array or nested-composite-element tags, declared in a Hibernate mapping file, with access of type property, but no setter method is found with such name in the corresponding class.

    Setter Method Not Found Example

  • Type Mismatch
    Reports any type attribute of id, version, property or key-property, declared in a Hibernate mapping file, that doesn't match the type declared in its associated field, getter or setter.

    Type Mismatch Example

  • Wrong Collection of Elements Type
    Reports any field or property annotated with the @CollectionOfElements annotation and whose type is not any of the following: array of Java primitive types; collections or maps of core types (primitive wrapper types, java.lang.String, java.math.BigInteger, java.math.BigDecimal, java.util.Date, java.util.Calendar, java.sql.Date, java.sql.Time, java.sql.Timestamp); collections or maps of embeddable classes.

    Wrong Collection of Elements Type Example

  • Wrong Discriminator Type
    Reports any discriminator type or meta-type attribute, declared in a Hibernate mapping file, that is not any of the following: string, character, integer, byte, short, boolean, yes_no, true_false or a custom UserType.

    Wrong Discriminator Type Example

  • Wrong Version Type
    Reports 1) any version type attribute, declared in a Hibernate mapping file, that is not any of the following: long, integer, short, timestamp, calendar or a custom UserVersionType; or 2) any @Version field or property whose type is not any of the following: int, java.lang.Integer, short, java.lang.Short, long, java.lang.Long, java.sql.Timestamp or a custom UserVersionType.

    Wrong Version Type Example

EJB3 Persistence issues (Hibero)

  • Ambiguous Primary Key Definition
    Reports any primary key of an entity class being defined as simple and composite at the same time. A primary key must either be defined as simple or composite but not both.

    Ambiguous Primary Key Definition Example

  • Composite Primary Key Field Or Property Type Mismatch
    Reports any composite primary key field or property of an entity class, defined with the @IdClass annotation, whose type does not match to its corresponding field or property of the composite primary key class.

    Composite Primary Key Field or Property Type Mismatch Example

  • Duplicate Primary Key
    Reports any simple and/or composite primary key defined multiple times in an entity class. A simple primary key must correspond to a single persistent field or property. The @Id annotation is used to denote a simple primary key. A composite primary key, when defined with the annotation @EmbeddedId, must correspond to a single persistent field or property. There must be only one @EmbeddedId annotation and no @Id annotation when the @EmbeddedId annotation is used.

    Duplicate Primary Key Example

  • Embeddable Class Must Be A Top-Level Class
    Reports any embeddable class which isn't a top-level class.

    Embeddable Class Must Be a Top-level Class Example

  • Embeddable Class Must Be Serializable
    Reports any embeddable class which doesn't implement the java.io.Serializable interface. This is a hard requirement only if the embeddable class is to be passed by value as a detached object (e.g., through a remote interface).

    Embeddable Class Must Be Serializable Example

  • Embeddable Class Must Have A No-Arg Constructor
    Reports any embeddable class which doesn't provide a default no-argument constructor.

    Embeddable Class Must Have a No-arg Constructor Example

  • Embeddable Class Must Not Be Final
    Reports any embeddable class declared final.

    Embeddable Class Must Not Be Final Example

  • Embeddable No-Arg Constructor Must Be Public Or Protected
    Reports any no-arg constructor of an embeddable class not being declared public or protected.

    Embeddable No-arg Constructor Must Be Public or Protected Example

  • EmbeddedId Composite Primary Key Class Must Be Embeddable
    Reports any composite primary key defined with the EmbeddedId annotation and mapped to a class not declared as embeddable.

    EmbeddedId Composite Primary Key Class Must Be Embeddable Example

  • Entity Class Must Be A Top-Level Class
    Reports any entity class which isn't a top-level class.

    Entity Class Must Be a Top-level Class Example

  • Entity Class Must Be Serializable
    Reports any entity class which doesn't implement the java.io.Serializable interface. This is a hard requirement only if the entity class is to be passed by value as a detached object (e.g., through a remote interface).

    Entity Class Must Be Serializable Example

  • Entity Class Must Have A No-Arg Constructor
    Reports any entity class which doesn't provide a default no-argument constructor.

    Entity Class Must Have a No-arg Constructor Example

  • Entity Class Must Not Be Final
    Reports any entity class declared final.

    Entity Class Must Not Be Final Example

  • Entity No-Arg Constructor Must Be Public Or Protected
    Reports any no-arg constructor of an entity class not being declared public or protected.

    Entity No-arg Constructor Must Be Public or Protected Example

  • GeneratedValue May Be Defined In Primary Key Only
    Reports any GeneratedValue annotation defined in a non-primary key. The @GeneratedValue annotation may be applied to a primary key property or field of an entity or mapped superclass in conjuntion with the @Id annotation.

    GeneratedValue May Be Defined in Primary Key Only Example

  • Mapping Annotations Applied To Both Persistent Fields And Properties
    Reports any entity class having mapping annotations applied to both persistent fields and properties.

    Mapping Annotations Applied To Both Persistent Fields and Properties Example

  • Mapping Annotations Not Applicable To Setter Accessors
    Reports any setter property accessors of an entity class having object/relational mapping annotations. When property-based access is used, the object/relational mapping annotations for the entity class annotate the getter property accessors.

    Mapping Annotations Not Applicable To Setter Accessors Example

  • Mapping Annotations Not Applicable To Transient Fields Or Properties
    Reports any fields or properties of an entity class declared transient or annotated @Transient having object/relational mapping annotations. Mapping annotations cannot be applied to fields or properties that are transient or @Transient.

    Mapping Annotations Not Applicable To Transient Fields or Properties Example

  • Missing Composite Primary Key Class Persistent Fields Or Properties
    Reports any entity class, having a composite primary key defined with the @IdClass annotation, which does not map all the persistent fields or properties of the composite primary key class.
    All the persistent fields or properties (depending on the access type) of the composite primary key class must be mapped to multiple fields or properties of the entity class.

    Missing Composite Primary Key Class Persistent Fields or Properties Example

  • Missing Primary Key
    Reports any root entity class not having defined a primary key. The primary key must be defined on the entity that is the root of the entity hierarchy or on a mapped superclass of the entity hierarchy.

    Missing Primary Key Example

  • Missing Relationship Target Entity
    Reports any many relationship modeling annotation (namely @OneToMany and @ManyToMany) which does not specify a target entity and it cannot be inferred from the annotated field or property type (i.e., Java generics are not used for collections).

    Missing Relationship Target Entity Example

  • Multiple Version Fields Or Properties
    Reports multiple declarations of a @Version field or property in an entity class. Only a single @Version field or property should be used per class; applications that use more than one @Version field or property will not be portable.

    Multiple Version Fields or Properties Example

  • Persistent Field Must Not Be Final
    Reports any persistent field of an entity or embeddable class declared final.

    Persistent Field Must Not Be Final Example

  • Persistent Field Must Not Be Public
    Reports any persistent field of an entity or embeddable class declared public.

    Persistent Field Must Not Be Public Example

  • Persistent Method Must Not Be Final
    Reports any persistent method of an entity or embeddable class declared final.

    Persistent Method Must Not Be Final Example

  • Primary Key Class Must Be Public
    Reports any primary key class (for composite primary keys) not being declared public.

    Primary Key Class Must Be Public Example

  • Primary Key Class Must Be Serializable
    Reports any primary key class (for composite primary keys) not being serializable (i.e., implements java.io.Serializable).

    Primary Key Class Must Be Serializable Example

  • Primary Key Class Must Define equals() and hashCode()
    Reports any primary key class (for composite primary keys) which does not override equals() and hashCode().
    The semantics of value equality for these methods must be consistent with the database equality for the database types to which the key is mapped.

    Primary Key Class Must Define equals() and hashCode() Example

  • Primary Key Class Must Have A No-Arg Constructor
    Reports any primary key class (for composite primary keys) which doesn't provide a default no-argument constructor.

    Primary Key Class Must Have a No-arg Constructor Example

  • Primary Key Class No-Arg Constructor Must Be Public
    Reports any no-arg constructor of a primary key class (for composite primary keys) not being declared public.

    Primary Key Class No-arg Constructor Must Be Public Example

  • Primary Key Class Properties Must Be Public Or Protected
    Reports any primary key class (for composite primary keys) properties not being declared public or protected, when property-based access is used.

    Primary Key Class Properties Must Be Public or Protected Example

  • Primary Key Must Be Defined Exactly Once In The Entity Hierarchy
    Reports any primary key not declared in a root entity or mapped superclass. The primary key must be defined exactly once in an entity hierarchy (on the entity that is the root of the entity hierarchy or on a mapped superclass of the entity hierarchy).

    Primary Key Must Be Defined Exactly Once In The Entity Hierarchy Example

  • Property Accessor Must Be Public Or Protected
    Reports any property accessor of an entity class not being declared public or protected.

    Property Accessor Must Be Public Or Protected Example

  • Redundant Relationship Target Entity
    Reports any relationship modeling annotation which does specify a target entity and it can be inferred from the annotated field or property type.

    Redundant Relationship Target Entity Example

  • Unknown Composite Primary Key Field Or Property
    Reports any composite primary key field or property of an entity class, defined with the @IdClass annotation, whose name does not correspond to any field or property of the composite primary key class.

    Unknown Composite Primary Key Field Or Property Example

  • Unresolved Symbol
    Reports any EJB3 Persistence and Hibernate annotation member value (i.e., attribute value) referencing a symbol which cannot be resolved (e.g., reference to an unknown package, class, field, property, etc.).

    Unresolved Symbol Example

  • Wrong Composite Primary Key Definition
    Reports any primary key field or property defined as composite with @EmbeddedId in an entity class annotated with @IdClass. A composite primary key must correspond to either a single persistent field or property annotated with @EmbeddedId or to a set of such fields or properties annotated with @Id used in conjuntion with the @IdClass annotation.

    Wrong Composite Primary Key Definition Example

  • Wrong Composite Primary Key Type
    Reports any field or property of an entity class, defined as a composite primary key (using the @EmbeddedId annotation), whose type or returned type is not a class. A primary key class must be defined to represent a composite primary key.

    Wrong Composite Primary Key Type Example

  • Wrong Lob Type
    Reports any @Lob field or property whose type is not any of the following: byte[]; java.lang.Byte[]; char[]; java.lang.Character[]; java.lang.String; java.sql.Blob; java.sql.Clob; java.io.Serializable.

    Wrong Lob Type Example

  • Wrong Persistent Field Or Property Type
    Reports any persistent field or property whose type is not any of the following: any Java primitive type; any primitive wrapper type; java.lang.String; java.math.BigInteger; java.math.BigDecimal; java.util.Date; java.util.Calendar; java.sql.Date; java.sql.Time; java.sql.Timestamp; any user-defined serializable type; byte[]; Byte[]; char[]; Character[]; enums; entity types and/or collections of entity types; embeddable classes.

    Wrong Persistent Field Or Property Type Example

  • Wrong Primary Key Type
    Reports any primary key field or property whose type is not any of the following: any Java primitive type; any primitive wrapper type; java.lang.String; java.util.Date; java.sql.Date.

    Wrong Primary Key Type Example

  • Wrong Version Type
    Reports any @Version field or property whose type is not any of the following: int; java.lang.Integer; short; java.lang.Short; long; java.lang.Long; java.sql.Timestamp.

    Wrong Version Type Example