We are getting the exception in the log as below line, when the column is not matched with database column. But it is not throwing the exception. I have even kept the try catch. How can i catch the exception?
WARN 2015-11-04 17:25:44,055 [http-apr-8080-exec-4][SqlExceptionHelper.java:144] : SQL Error: 904, SQLState: 42000 ERROR 2015-11-04 17:25:44,055 [http-apr-8080-exec-4][SqlExceptionHelper.java:146] : ORA-00904: "SH_RATE_DESCRIPTIO": invalid identi fier
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import com.core.model.entity.ShippingTable;
@Repository("sTableDAO")
public class STableDao {
@PersistenceContext(unitName = "somaUnit")
private EntityManager entityManager;
public STable save(STable sTable) {
try{
sTable = entityManager.merge(sTable);
}catch(Exception e){
e.printStackTrace();
}
return sTable;
}
}
Try to get message from DataIntegrityViolationException
catch (DataIntegrityViolationException ex) {
handleException(ex.getRootCause().getMessage()) /*get the message and handle it*/
}
Just set the loglevel for this logger to fatal. In the code:
private static Logger logger = org.apache.log4j.Logger.getLogger("org.hibernate.engine.jdbc.spi.SqlExceptionHelper");
logger.setLevel(Level.FATAL);
Or:
...
<!-- ADDED THE FOLLOWING -->
<logger category="org.hibernate.engine.jdbc.spi.SqlExceptionHelper">
<level name="FATAL"/>
</logger>
...
Level.FATAL
even swallowed the error log message. Setting
org.apache.log4j.Logger.getLogger("org.hibernate.engine.jdbc.spi.SqlExceptionHelper")
.setLevel(Level.ALL);
In a static
initializer block of some arbitrary class did the trick!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With