16

in my Model project (it only has the persistent classes, aka java beans) i have a class which has a composite primary key. To map this, i have used two @Id in my class. Before hibernate 4 it was not possible but now it is Ok. So, the problem is, eclipse is showing an error in this class, saying that it should be done in the old way. Like this:

False error

As i said, it is a false error, because the code works fine if i execute it. I have JBoss Tools plugin installed on eclipse, but i don't know if the errors is being caused by it or by eclipse.

Anyone know how to solve this issue? Not that it is preventing me from executing the app, but it is an annoying thing to have the error being always shown.

--- EDIT ---

So, now i know the problem is on JBoss Tools because i deactivated the JPA facet on the project and the error have stopped. But i wish i could use the facilities that JBoss Tools gives, so... no solution yet.

Mateus Viccari
  • 7,389
  • 14
  • 65
  • 101
  • I did not know it is possible in Hibernate 4 :) Found out from the question. I was going to propose the EmbeddedId with an Embeddable class. – Hrishikesh Jan 15 '14 at 10:44
  • JPA Facet is not a part of JBoss Tools, it comes form Eclips Daly project which is in turn part of Webtools project. JBoss Tools is based on Webtools. You can ask questions like this on JBoss Tools Users Forum here - https://community.jboss.org/en/tools. – dgolovin Jan 22 '14 at 17:47
  • so you need IdClass, as per the JPA spec then – Neil Stockton Jan 09 '15 at 18:28

2 Answers2

33

Well it's almost a year late, but I just came across this problem myself today :-)

You can turn off this error in Eclipse. Go to

Preferences->Java Persistence->JPA->Errors/Warnings

Under the Type section look for the category "ID class must be used when multiple ID mappings defined." and change it from Error to Ignore (or whatever severity you want to give it).

petroman
  • 354
  • 3
  • 4
2

well if you have a composite key u should also have a composite key class

something mapped like this:

@Entity
@IdClass(PK_BP.class)
@Table(name="BP_BIS")
public class BP_BIS implements Serializable
{
    private static final long serialVersionUID = 1L;

    @Id  
    private String BP_MODE;
    @Id  
    private String BP_BD;

the composite key class will be like this :

public class PK_BP implements Serializable
{
    private static final long serialVersionUID = 1L;

    private String BP_MODE;
    private String BP_BD;

    public PK_BP()
    {}

    public PK_BP(String bP_MODE, String bP_BD) {
        this.BP_MODE = bP_MODE;
        this.BP_BD = bP_BD;
    }

}
BaN3
  • 435
  • 1
  • 3
  • 16
  • Op specifically asked for the new way without a composite key. – Leonard Brünings Jan 15 '14 at 11:01
  • This doesn't really answer this specific question, but I came across this question/answer when searching for the error, and how to create an id class was what I was looking for. If anyone else is in the same boat, this other answer provides a pretty good id class example: https://stackoverflow.com/a/18890592/3249197 – starwarswii Jun 28 '19 at 13:26