-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate throws ConstraintViolationException during flush
PostPosted: Wed Oct 25, 2017 2:52 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 44
Hi experts,

I am receiving yet another org.hibernate.exception.ConstraintViolationException : could not execute statement. I did a System.out.println and my NRIC is printed so I am not sure why it says null is not allowed. Hope someone can tell me how to resolve the problem.

Here's the full stack of the error message :

Code:
2017-Oct-25 14:37:31 PM [http-nio-8013-exec-1] INFO  org.hibernate.Version - HHH000412: Hibernate Core {5.0.0.Final}
2017-Oct-25 14:37:32 PM [http-nio-8013-exec-1] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
2017-Oct-25 14:37:32 PM [http-nio-8013-exec-1] INFO  org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
2017-Oct-25 14:37:37 PM [http-nio-8013-exec-1] INFO  util.HibernateUtil - Hibernate Configuration loaded
2017-Oct-25 14:37:40 PM [http-nio-8013-exec-1] INFO  org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
2017-Oct-25 14:37:41 PM [http-nio-8013-exec-1] WARN  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000402: Using Hibernate built-in connection pool (not for production use!)
2017-Oct-25 14:37:41 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000401: using driver [com.mysql.jdbc.Driver] at URL [jdbc:mysql://localhost:3306/hi5]
2017-Oct-25 14:37:41 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000046: Connection properties: {user=root, password=****}
2017-Oct-25 14:37:41 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000006: Autocommit mode: false
2017-Oct-25 14:37:41 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000115: Hibernate connection pool size: 20 (min=1)
2017-Oct-25 14:37:42 PM [http-nio-8013-exec-1] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
2017-Oct-25 14:37:46 PM [http-nio-8013-exec-1] INFO  org.hibernate.tool.hbm2ddl.SchemaUpdate - HHH000228: Running hbm2ddl schema update
2017-Oct-25 14:37:49 PM [http-nio-8013-exec-1] INFO  util.HibernateUtil - sessionFactory created.
2017-Oct-25 14:37:49 PM [http-nio-8013-exec-1] DEBUG org.hibernate.SQL - insert into tutor (tutorNRIC, tutorAddress1, tutorAddress2, tutorAge, tutorRates, tutorContactNo, tutorEmail, tutorGender, tutorName, tutorQualification, tutorQualficationDetail, tutorRemarks, subjMany, zipcode, tutor_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into tutor (tutorNRIC, tutorAddress1, tutorAddress2, tutorAge, tutorRates, tutorContactNo, tutorEmail, tutorGender, tutorName, tutorQualification, tutorQualficationDetail, tutorRemarks, subjMany, zipcode, tutor_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
2017-Oct-25 14:37:49 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [1] as [VARCHAR] - [null]
2017-Oct-25 14:37:49 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [2] as [VARCHAR] - [null]
2017-Oct-25 14:37:49 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [3] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [4] as [INTEGER] - [0]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [5] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [6] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [7] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [8] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [9] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [10] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [11] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [12] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [13] as [VARBINARY] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [14] as [VARCHAR] - [null]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] TRACE org.hibernate.type.descriptor.sql.BasicBinder - binding parameter [15] as [INTEGER] - [0]
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] WARN  org.hibernate.engine.jdbc.spi.SqlExceptionHelper - SQL Error: 1048, SQLState: 23000
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] ERROR org.hibernate.engine.jdbc.spi.SqlExceptionHelper - Column 'tutorNRIC' cannot be null
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.batch.internal.AbstractBatchImpl - HHH000010: On release of batch it still contained JDBC statements
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] ERROR org.hibernate.internal.SessionImpl - HHH000346: Error during managed flush [could not execute statement]
org.hibernate.exception.ConstraintViolationException: could not execute statement
   at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:59)
   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
   at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
   at org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2823)
   at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3323)
   at org.hibernate.action.internal.EntityInsertAction.execute(EntityInsertAction.java:89)
   at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)
   at org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)
   at org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)
   at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
   at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)
   at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)
   at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2890)
   at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2266)
   at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
   at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
   at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
   at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230)
   at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
   at DAOSql.tutorDAOImpl.insertTutor(tutorDAOImpl.java:50)
   at Business.Manager.insertTutor(Manager.java:21)
   at controller.tutorController.doPost(tutorController.java:133)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
   at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
   at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
   at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
   at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
   at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
   at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
   at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
   at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
   at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
   at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
   at java.lang.Thread.run(Unknown Source)
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'tutorNRIC' cannot be null
   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
   at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
   at java.lang.reflect.Constructor.newInstance(Unknown Source)
   at com.mysql.jdbc.Util.handleNewInstance(Util.java:404)
   at com.mysql.jdbc.Util.getInstance(Util.java:387)
   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:934)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3870)
   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3806)
   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2470)
   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2617)
   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2550)
   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1861)
   at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2073)
   at com.mysql.jdbc.PreparedStatement.executeUpdateInternal(PreparedStatement.java:2009)
   at com.mysql.jdbc.PreparedStatement.executeLargeUpdate(PreparedStatement.java:5094)
   at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1994)
   at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
   ... 44 more
2017-Oct-25 14:37:50 PM [http-nio-8013-exec-1] INFO  org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl - HHH000030: Cleaning up connection pool [jdbc:mysql://localhost:3306/hi5]



Top
 Profile  
 
 Post subject: Re: org.hibernate.exception.ConstraintViolationException:
PostPosted: Wed Oct 25, 2017 3:08 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
From the log, I see that all bind variables are either null or 0, which means you did something like:

Code:
entityManager.persist(new Tutor());


Check your code or debug it to figure out here you do that.

You could also use Bean Validation to catch these error before they propagate to the DB.


Top
 Profile  
 
 Post subject: Re: org.hibernate.exception.ConstraintViolationException:
PostPosted: Wed Oct 25, 2017 4:06 am 
Beginner
Beginner

Joined: Tue Aug 08, 2017 12:14 am
Posts: 44
vlad wrote:
From the log, I see that all bind variables are either null or 0, which means you did something like:

Code:
entityManager.persist(new Tutor());


Check your code or debug it to figure out here you do that.

You could also use Bean Validation to catch these error before they propagate to the DB.


Hi vlad,

I wasn't using entityManager cos it is deprecated since Hibernate 3 right ? I am using Hibernate code.

Her'e how I do it and then there's a controller which will read in the service layer code and the parameter from the jsp page.

Code:
public class tutorDAOImpl implements tutorDAO {

   // private final String INSERT_QYR1 = null;
   // List<tutor> tutors;

   private static Logger log = Logger.getLogger( tutorDAOImpl.class );

   

   public void insertTutor(Tutor m) throws Exception {
         SessionFactory sessionFactory = null;
         try{
         sessionFactory = HibernateUtil.getSessionFactory();
         Session session = sessionFactory.getCurrentSession();
         org.hibernate.Transaction tx = session.beginTransaction();
         //   em = emf.createEntityManager();   
      //   em.getTransaction().begin();
           m = new Tutor();
         m.setName(m.getName());
         m.setNRIC(m.getNRIC());
         m.setEmail(m.getEmail());
etc


Basically, I just take a DAO pattern code and adapt to Hibernate framework. Is it possible to do it like that ?

Or do you have a straight forward tutorial on using DAO and JSP ?


Top
 Profile  
 
 Post subject: Re: Hibernate throws ConstraintViolationException during flush
PostPosted: Wed Oct 25, 2017 5:48 am 
Hibernate Team
Hibernate Team

Joined: Thu Sep 11, 2014 2:50 am
Posts: 1628
Location: Romania
Quote:
I wasn't using entityManager cos it is deprecated since Hibernate 3 right ? I am using Hibernate code.


Of course, it's not deprecated. Hibernate implements the JPA standard, and the EntityManager is part of the standard API.

Quote:
Basically, I just take a DAO pattern code and adapt to Hibernate framework. Is it possible to do it like that ?


It's ok to use a DAO layer. But it's even better to use Java EE or Spring for that and have the Hibernate Session and the Transaction managed automatically.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.