Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse: No generator named "system-uuid" is defined in the persistence unit

I have a maven enabled project imported into Eclipse. From Eclipse, I get an error "No generator named "system-uuid" is defined in the persistence unit" on the system-uuid portion of the following lines:

@Id @GeneratedValue(generator = "system-uuid")
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@Column(length = 36)
public String getId() {
    return id;
}

The project builds correctly from the command line. What is causing Eclipse to generate this error and how do I fix it?

The persistence file looks like this..

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence 
    http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
    version="1.0">
    <persistence-unit name="xxxx"/>
</persistence>
like image 935
cmdematos Avatar asked Sep 17 '12 18:09

cmdematos


3 Answers

You can turn the error off/down under Preferences -> Java Persistence -> JPA -> Errors/Warnings under 'Queries and Generators' by changing the error 'Generator is not defined in the persistence unit' to a warning.

This looks like a bug in the Hibernate Tools extension of Dali in Eclipse.You could report this to Hibernate Tools or maybe this is fixed in a more recent version.

like image 124
Karen Butzke Avatar answered Nov 11 '22 02:11

Karen Butzke


Eclipse Luna: This seems to work

Project -> Clean
like image 45
jeff Avatar answered Nov 11 '22 03:11

jeff


Newer versions of Eclipse' JPA support seem to depend on the order of Annotations. You are defining the generator after you try to use em.

This will work:

@Id
@GenericGenerator(name = "system-uuid", strategy = "uuid")
@GeneratedValue(generator = "system-uuid")
@Column(length = 36)
public String getId() {
    return id;
}

However the order of annotations in Java must not have a meaning. So Karen is right, it seems to be a bug.

like image 6
roehrijn Avatar answered Nov 11 '22 03:11

roehrijn