6

I'm currently having this issue which I don't have before I migrated to eclipse-jee-kepler. What I have:

I have 2 classes, base and the extending class:

public abstract class BaseEntity implements Serializable {
    @Id
    @GeneratedValue(generator = "ID_GENERATOR")
    @Column(name = "ID")
    private Long id;
}

@Entity
@Table(name = "CUSTOMER")
@SequenceGenerator(name = "ID_GENERATOR", sequenceName = "CUSTOMER_SEQ")
public class Customer extends BaseEntity {
}

Before I don't have this validation error but now eclipse is throwing it. I can compile, build and deploy successfully but the error marker is making it hard to pinpoint the compile errors when you really have one.

The error seems obvious, it's because I have ID_GENERATOR on all the extending classes. My question: 1.) Can I ignore this error? 2.) Any work around? Possibly using a different approach.

czetsuya
  • 4,773
  • 13
  • 53
  • 99

3 Answers3

16

I figured the problem, it was more of an eclipse JPA validation setting. To disable:

  1. Select Window » Preferences
  2. Expand Java Persistence » JPA » Errors/Warnings
  3. Click Queries and generators
  4. Set Duplicate generator defined to: Ignore
  5. Click OK to apply changes and close the dialog

You can also set the value to Warning instead of Ignore.

Dave Jarvis
  • 30,436
  • 41
  • 178
  • 315
czetsuya
  • 4,773
  • 13
  • 53
  • 99
  • 8
    Could it actually cause an error to occur, or two entities to use the same generator sequence unintentionally? I ask because hiding the warning/error doesn't make the condition go away :) – David Mann May 08 '14 at 17:58
4

The generator's name must to be unique by generator and it can be referenced by one or more classes.

The javadoc clearly says:

(Required) A unique generator name that can be referenced by one or more classes to be the generator for primary key values.

According to the java JPA 2.1 specification (SequenceGenerator Annotation of the JPA 2.1 - section 11.1.48):

The scope of the generator name is global to the persistence unit (across all generator types)

Ariel Carrera
  • 5,113
  • 25
  • 36
3

For MyEclipse

1.Windows->Preferences

2.Myeclipse->Validation->JPA

3.Queries and generators

Generators is not defined in the persistence unit;

Kevin
  • 31
  • 2