Java @GeneratedValue + SQL server NEWID + Hibernate

0

I have a table that has ID set to CREATE DEFAULT ID_Tabelas AS NEWID() , that is, even if I use an insert without the key, it will be generated automatically. How can I do with hibernate to recognize that the database itself will generate the table key?

If I use annotations @GeneratedValue(strategy = GenerationType.AUTO) or @GeneratedValue(strategy = GenerationType.IDENTITY) , I get the following error:

SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-17) javax.faces.el.EvaluationException: org.hibernate.AssertionFailure: null identifier

If I use annotaion @GeneratedValue(strategy = GenerationType.TABLE) , I get the error:

SEVERE [javax.enterprise.resource.webcontainer.jsf.context] (default task-17) javax.faces.el.EvaluationException: org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

The ID is denoted in the entity as:

@Id
@GeneratedValue(strategy = GenerationType.AUTO) //??
@Column(name = "id", length = 36, updatable = false, nullable = false)
private String id;
    
asked by anonymous 24.01.2018 / 11:44

1 answer

0

Add this property to my file:

<property name="hibernate.id.new_generator_mappings" value="false" />

Help - link

Or you can create a sequence in your table.

@SequenceGenerator(name="sua_table_id_seq", sequenceName =  "sua_table_id_seq")
@GeneratedValue(strategy = GenerationType.AUTO, generator = "sua_table_id_seq")
@Id
@Column(name = "id", length = 36, updatable = false, nullable = false)
private String id;
    
24.01.2018 / 14:02