hibernate h2 embeddable list expected “identifier”

纵饮孤独 提交于 2019-12-10 13:14:20

问题


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


回答1:


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!




回答2:


try to put the ; before the " and test ?




回答3:


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




回答4:


I had the same problem with Spring and H2 database for tests, My entity had the field name "interval", I renamed to "inter" and resolved the problem.

So, these errors happen due to a sql reserved names in entities.



来源:https://stackoverflow.com/questions/46737430/hibernate-h2-embeddable-list-expected-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!