#Hibernate unique not working

23 messages · Page 1 of 1 (latest)

scenic drum
#

This is the code i used to make it

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    int id;

    @Column(name = "question", nullable = false, length = 999, unique = true)
    String question;

    @Column(name = "awnser", nullable = false, length = 999, unique = true)
    String awnser;

    @Column(name = "test", length = 999, unique = true)
    String test;
shell nicheBOT
#

This post has been reserved for your question.

Hey @scenic drum! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

mint cliff
#

what do you mean its not working?

scenic drum
#

But i did make it unique in the code

mint cliff
#

which database are you usingf

scenic drum
#

MySQL

#

is it possible that there is only 1 unique per table?

mint cliff
#

no that is primary key

#

are you using spring boot?

scenic drum
#

no

#
    @Column(name = "awnser", nullable = false, length = 999, unique = true)
    String awnser;
#

thats the part i wanna make unique

mint cliff
#

did you try manually creating the table

#

there might be max varchar length for unique key

scenic drum
#

eehmmm

#

i havent

#

ill put the length to like 10

#

u were right

#

thank you somuch

shell nicheBOT
# scenic drum thank you somuch

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.