Prevent duplicate entries in column using hibernate
If I understood what you are asking I think you can annotate the both attributes with:
@Column(unique = true)
It will make your attributes unique, so you will ensure that the data won't be duplicated.
Best way to prevent duplicate rows in database
First, you don't need @Component
on your entity.
Second, add this annotation
@Table(name = "table_name", uniqueConstraints={@UniqueConstraint(columnNames ={"id", "departure", ...})})
with fields that should not be duplicated.
NB: you need to add spring.jpa.hibernate.ddl-auto=update
to application.properties
Related Topics
How to Fill Hashmap from Java Property File With Spring @Value
How to Create Unique Column With Jpa
Java Socket Api: How to Tell If a Connection Has Been Closed
Spring Rest Post Json Requestbody Content Type Not Supported
Java.Exe Finished With Non-Zero Exit Value 1
How to Get Values of All Elements from Xml String in Java
Spring Data JPA - Consider Defining a Bean Named 'Entitymanagerfactory' in Your Configuration
Spring Security - 405 Request Method 'Post' Not Supported
Forwarding the Request from One Jsp to Another Jsp With All Request Parameters
Arraylist - How to Check If an Index Exists
Spring Junit: How to Mock Autowired Component in Autowired Component
Jpa:How to Convert a Native Query Result Set to Pojo Class Collection
How to Configure Hikaricp in My Spring Boot App in My Application.Properties Files
Wait Until All Threads Finish Their Work in Java
How to Get a List of All the Implementations of an Interface Programmatically in Java