Which is more efficient -> hibernate criteria-mysql query? -


I am developing a web based application using spring and hibernate-mySQL. I have a restriction that the user's name should be unique, which is a more efficient way? To use the Hibernate criteria to check the user? Or define unique in the database and then use a try hold?

Thank you in advance ..

You should use both. In hibernation the query will allow the functionality to check the functionality that it does not exist before the user is inserted, and return a proper result or enter the appropriate exception, it is better to rely on a unique obstacle, Due to rollback with a secret error message, exceptions will be hidden within the stack.

But you should also have a unique barrier to guarantee uniqueness in the case of two concurrent threads, check that the user is not present at the same time, then insert both the same user at the same time.

For general questions that do not need to be dynamically composed I will use the HQL instead of criteria: Read more IMHO

Comments

Popular posts from this blog

Python SQLAlchemy:AttributeError: Neither 'Column' object nor 'Comparator' object has an attribute 'schema' -

java - How not to audit a join table and related entities using Hibernate Envers? -

mongodb - CakePHP paginator ignoring order, but only for certain values -