Java @Generatedvalue + SQL server NEWID + Hibernate

Asked

Viewed 236 times

0

I have a table that has ID defined as CREATE DEFAULT ID_Tabelas AS NEWID(), that is, even if I use an Insert without the key, it will be generated automatically. How to make Hibernate recognize that the bank itself will generate the table key?

If I use the 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), 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 denifido in the entity as:

@Id
@GeneratedValue(strategy = GenerationType.AUTO) //??
@Column(name = "id", length = 36, updatable = false, nullable = false)
private String id;
  • Take a look at this answer in the English OS, it might help you: https://stackoverflow.com/a/3079671/4730201

  • which version of SQL Server ?

  • @LR10 version 2008

  • Didn’t work out ? with Quence?

  • It worked, @Ricardopunctual. Thank you very much!

1 answer

0

Add this property to my archive:

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

Helping - https://hibernate.atlassian.net/browse/HHH-11014

or you can create a Quence 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;
  • It only works if I remove strategy = GenerationType.AUTO

  • remove then. Your sequense will already do so puts IDENTITY!!

  • If it worked out vote on the answer to other people also use.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.