Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7652617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:49:08+00:00 2026-05-31T11:49:08+00:00

I have an Entity with the field url , this entity is being persisted

  • 0

I have an Entity with the field url, this entity is being persisted to the database uppon sending a form based on the same entity.

I can set constraints to the form type in validation.yml along with custom messages like NotBlank and Url. That’s all fine. But when I try to persist an entity that already exists in the DB I get an error saying that the value already exists (url).

How can I set a custom message for this UniqueEntity constraint?

I tried adding UniqueEntity in the validation.yml, but it is in a different namespace and I cannot understand how it works, or how to setup it. It is there by default, couse url is defined as unique field in the original entity annotation, but how to change the error message??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T11:49:10+00:00Added an answer on May 31, 2026 at 11:49 am

    I just found a solution to my own problem.

    All validations can be defined in validation.yml, but since I am using annotations to define my entities, it is better to put all validations, messages etc. inside those annotations.

    It was enought to set @Assert\NotBlank for a not blank field and @ORM\UniqueEntity(message="my custom error") for the being unique validation.

    I’m sorry for flooding the site with my question, but I hope someone might find this useful..

    P.S.: Annotations or YML makes no difference, the setup is the same. I suppose in my case it should have been something like:

    Namespace\Class:
        constraints:
            - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
                fields: url
                message: "My custom message"
    

    It is quite flexible, thought I don’t see how we could set different messages if different fields are already present in the db…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How can I give set foreign key value field in Entity Framework. I have
I have a field aliases of type java.util.Set in one Entity . This Set
I have form with checkboxes loaded from database (I use entity field type). Checkboxes
I have an entity in EF4 that represents a device in the field being
A have a JPA entity that has timestamp field and is distinguished by a
I have entity model like this (using EclipseLink and JPA 2.0): @Entity class A
I want to make a form in which I can update my entity in
I have a Entity with a field which I want to be an Enum.
For example, I have a URL, that someone entered into a specific CMS form
I have a User entity that has a Current Location field (city and country).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.