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 8012295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:17:18+00:00 2026-06-04T19:17:18+00:00

Am not sure my title is explicit enough. here is what i mean.I’m developing

  • 0

Am not sure my title is explicit enough. here is what i mean.I’m developing a web application using spring 3.0.5 + hibernate 3.6.1.RELEASE with JPA annotation using sessionFactory.The application allows users to signup using username, email and password.

users can log in using (username or email) and password. I’m trying to find a reliable way to tell there is a unique contraint exception expressed as

java.sql.BatchUpdateException: Duplicate entry 'myusername' for key 'USERNAME' or org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update

if i could get a specific exception i could notify the user that his username or email is already taken.

What comes to my mind is to do a select before to check but then that doesn’t sound right to me.Any other solution ? what’s the best practice?

Thanks for reading this

  • 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-06-04T19:17:20+00:00Added an answer on June 4, 2026 at 7:17 pm

    Actually best practice would be to check if a user with that username/email address already exists when creating a new user. If it does then return something to indicate a failure, otherwise create the user.

    Generally you shouldn’t rely on database constraints for enforcing business rules.

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

Sidebar

Related Questions

Ok, I'm not sure that my title was clear enough, but I will try
not sure of what to put as the title here, but basically I am
Not sure the title explains what I want to do, so here goes: I
I'm not sure how to title my question, but here goes. I am testing
So I'm not exactly sure if the title fits it best, but here's what
I'm not entirely sure the title is properly worded, but here's the situation... I
I not sure how to describe in the title.So,just give more information here. I
I am not sure the title is clear enough. I have a dataframe (see
I am not sure the title of this question covers what I mean. In
Not sure if the title makes much sense, but here is what I'm trying

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.