0

I want to use an autoincrement ID for a field that is a String, like this:

    @Id
    @GeneratedValue(strategy = TABLE, generator = "MY_GENERATOR")
    @TableGenerator(name = "NAME", table = "MY_TABLE", pkColumnName = "MY_COLUMN", pkColumnValue = "MY_REF", valueColumnName = "SOMETHING", allocationSize = 1)
    @Column(name = "COL", unique = true, nullable = false, length = 3)
    public String getFcvCval() {
        return this.fcvCval;
    } 

But I get an exception of type:

org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String 

I cannot change the type of the column (it needs to be String). Is there a way to map the generated Numerical ID to its String value?

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Mr.Eddart
  • 10,050
  • 13
  • 49
  • 77
  • 1
    Possible duplicate of [How to use @Id with String Type in JPA / Hibernate?](https://stackoverflow.com/questions/18622716/how-to-use-id-with-string-type-in-jpa-hibernate) – Mara Mar 13 '19 at 11:22
  • 1
    https://stackoverflow.com/questions/40177865/hibernate-unknown-integral-data-type-for-ids – Mara Mar 13 '19 at 11:22

1 Answers1

0
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@GenericGenerator(name="increment", strategy = "increment") 
private String fcvCval;

You can use like this and also add addition annotation

Max
  • 1