Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turn off "error" about missing no-arg constructor in Eclipse

I'm using open-jpa and as we know it's shipped with enhancer which could create non private no-arg constructor during enhancement. It works, however eclipse have problem with it. It's quite rational that it doesn't know anything what would happen during ant build, so is there any possibility to turn off this particular error The Java class for mapped type ... must define a non-private zero-argument constructor bounded to @Entity annotation?

like image 495
abc Avatar asked Jan 01 '14 13:01

abc


People also ask

Do you need a no-arg constructor?

You don't have to provide any constructors for your class, but you must be careful when doing this. The compiler automatically provides a no-argument, default constructor for any class without constructors. This default constructor will call the no-argument constructor of the superclass.

What is no-arg constructor in Java?

No-Arg Constructor - a constructor that does not accept any arguments. Parameterized constructor - a constructor that accepts arguments. Default Constructor - a constructor that is automatically created by the Java compiler if it is not explicitly defined.

What happens when the no args constructor is absent in the entity bean?

So if you won't have no-args constructor in entity beans, hibernate will fail to instantiate it and you will get `HibernateException`.

Why does JPA require no-arg constructor?

The JPA specification requires that all persistent classes have a no-arg constructor. This constructor may be public or protected. Because the compiler automatically creates a default no-arg constructor when no other constructor is defined, only classes that define constructors must also include a no-arg constructor.


1 Answers

This works for me (Eclipse Mars.1 Release 4.5.1)

Project / Properties / JPA / Errors/Warnings
Enable Project Specific Settings
 Type
  ID class must have a public no-arg constructor (change from Error to something else)
like image 125
Fred Liporace Avatar answered Sep 29 '22 19:09

Fred Liporace