I have created an entity with table name and column names. I have also added the uniquekey constraint for a column name. But when I run, it shows the following error ;
org.hibernate.tool.schema.spi.CommandAcceptanceException: Error executing DDL "alter table ingredient add constraint UK_co7ro6kyijhfik027h0y4d3n3 unique (ingredient_name).
java.sql.SQLSyntaxErrorException: Specified key was too long; max key length is 1000 bytes
After I run the spring boot application, I have tried to add the unique constraint manually in MySQL workbench. - DOES NOT WORK
I have added the below code - DOES NOT WORK
@Table(name = "ingredient", uniqueConstraints=@UniqueConstraint(name="uk_ingredient_name",columnNames="ingredient_name"))
@Column(name = "ingredient_name" ,unique = true)
private String ingredientName;
- Tried to create a table manually in Mysql workbench and tried to alter the column name with unique key later. THIS WORKS. But I want hibernate to do this for me.
@Entity
@Table(name = "ingredient")
public class Ingredient {
@Id
@Column(name="ingredient_id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(name = "ingredient_name" ,unique = true)
private String ingredientName;
I want to save the ingredients without any repetitions. I do not want duplicate entries. I have gone through other answers and none of those solutions helped me.