Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate h2 embeddable list expected "identifier"

I'm trying to associate a list of function (whom Embeddable) within my Employee Entity and H2 seems unhappy with this saying that it expected an "identifier"

Caused by: org.h2.jdbc.JdbcSQLException: Syntax error in SQL statement " CREATE TABLE EMPLOYEE_FUNCTIONS ( EMPLOYEE_EMPLOYEEID VARCHAR(255) NOT NULL, ACTIVE BOOLEAN NOT NULL, DEPARTMENTNUMBER INTEGER NOT NULL, DESCRIPTION VARCHAR(255), ORDER[*] INTEGER NOT NULL ) "; expected "identifier";

The thing is I already done that with an other project and I don't see why it doesn't work.

Employee.java

@Entity
public class Employee extends AbstractScheduleEntity<EmployeeSchedule> {
    public static final String ACOMBA_UNIQUE_FIELD = "acombaUnique";

    @Id
    @GenericGenerator(name = "sequence_id", strategy = 
    "ca.tecsar.core.sql.ServerSequenceGenerator")
    @GeneratedValue(generator = "sequence_id")
    @Column(name = "EmployeeID", unique = true, nullable = false)
    private String employeeID;
    @ElementCollection
    private List<Function> functions;

    //getter and setter
}

Function.java

@Embeddable
public class Function implements Serializable {
    private int order;
    private boolean active;
    private String description;
    private int departmentNumber;

    //getter and setter
}

I removed a few properties in Employee that wasn't necessary. What may cause this error? Is it because I have a String as identifier in my Employee? If so how can I tell to Hibernate to add Employee_EmployeeID as identifier? Thanks

like image 985
Nicolas Sagala Beaucage Avatar asked Oct 13 '17 20:10

Nicolas Sagala Beaucage


3 Answers

Turns out I was being dumb and named a column "Order". Wonder why H2 wasn't happy :upside_down:

Changed the variable name to something else and it worked!

like image 121
Nicolas Sagala Beaucage Avatar answered Nov 03 '22 04:11

Nicolas Sagala Beaucage


I have the same problem while naming the fields: private String to and private String from , changed to ex. dayTo , dayFrom , and it worked.

like image 8
pearinthemountains Avatar answered Nov 03 '22 05:11

pearinthemountains


Got same issue with Order as entity. Changed table name to "orderz" and goes on.

like image 4
tarmogoyf Avatar answered Nov 03 '22 05:11

tarmogoyf