Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does IntelliJ's JPA inspection tell me "more than one attribute configured for field 'id'"?

I have many JPA entity classes of the general form:

@Entity
@Table(name = "MY_TABLE", catalog = "", schema = "VBMSUI")
@NamedQueries({...})
public class MyEntity implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    @GeneratedValue(strategy=GenerationType.SEQUENCE,
            generator="MY_TABLE_ID_SEQ")
    @SequenceGenerator(name="MY_TABLE_ID_SEQ",
            sequenceName = "MY_TABLE_ID_SEQ")
    private BigDecimal id;
...
}

IntelliJ's inspection facility underlines "id" in red, and provides the message - "more than one attribute configured for field 'id'".

enter image description here

There are no other attributes in the class identifed as an id. There is a getter and a setter for "id", but they have no annotations. BTW, the code for the entity class was generated by NetBeans, and it seems to work.

What is happening, and how can I correct it?

like image 433
kc2001 Avatar asked Dec 21 '22 08:12

kc2001


2 Answers

This seems to happen because you have both @Id and @Basic annotations on the same attribute (quick fixes suggest removing either one of them). I'm no expert in JPA, but it looks valid to me, so perhaps it is a bug in IntelliJ's inspection, which should be reported in their bugtracker.

like image 126
Bastien Jansen Avatar answered Dec 26 '22 10:12

Bastien Jansen


It appears that this is a bug. It has been reported as such here: https://youtrack.jetbrains.com/issue/IDEA-129147 You can up-vote it if you wish to see a resolution.

like image 23
BamaPookie Avatar answered Dec 26 '22 12:12

BamaPookie