While throwing EntityUniqueConstraintException , getMessage() throws entire statck trace like "insert into <table name> values(<column names>) schemaname.constraintname constarint violation exception
That's not a stack trace, it looks like an SQL statement template, presumably it's the statement that caused the exception to be thrown.
I need to get schemaname.constraintname constarint violation exception alone.
Not 100% sure what you mean by this.
If want to get an earlier exception that ultimately caused the EntityUniqueConstraintException to be thrown you can work your way down the cause stack by repeatedly calling getCause() on the exception returned from previous call to getCause() until you find an exception of the type you are looking for and then call getMessage() on it.
subject: How to get exact error message from print stacktrace