This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
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