title: Nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
body: <p>I was kind of roped into using maven, Hibernate, spring and JPA repositories in a small project. I cheerfully assumed that information found here</p>
  
  <p><a href="http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/jpa.repositories.html" rel="nofollow noreferrer">http://docs.spring.io/spring-data/jpa/docs/1.4.2.RELEASE/reference/html/jpa.repositories.html</a></p>
  
  <p>will be enough to create at least a simple application. Unluckily that's not the case. I've managed to read data from a MySQL database, but as for now have been unable to insert any data.</p>
  
  <p>Here is a simple 'User' model class.</p>
  
  <pre><code>@Entity
  @Table(name = "ctuser")
  public class User implements Serializable {
  
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private long uid;
  
      @Column(name = "Gmail", nullable = false)
      private String gmail;
  
  
      public String getGmail() {
          return gmail;
      }
  
      public void setGmail(String gmail) {
          this.gmail = gmail;
      }
  
      @Override
      public String toString() {
          return getGmail();
      }
  }
  </code></pre>
  
  <p>I've created an appropriate repository interface...</p>
  
  <pre><code>package put.io.come_together.service.persistance.repository;
  
  import org.springframework.data.jpa.repository.JpaRepository;
  import put.io.come_together.model.User;
  
  public interface UserRepository extends JpaRepository&lt;User, Long&gt; {
  
      User findUserByUid(long uid);
  
      User save (User obj);
  
      }
  </code></pre>
  
  <p>...an interface for the service...</p>
  
  <pre><code>public interface UserService {
  
      User getUser(long uid);
  
      User addUser(User obj);
  
      List&lt;User&gt; getAll();
  
  }
  </code></pre>
  
  <p>...and implementation of the interface.</p>
  
  <pre><code>@Service
  public class UserServiceImpl implements UserService {
      private final UserRepository userRepository;
  
      @Autowired
      public UserServiceImpl(UserRepository userRepository) {
          this.userRepository = userRepository;
      }
  
      @Override
      public User getUser(long uid) {return userRepository.findUserByUid(uid);
      }
  
      @Transactional
      @Override
      public User addUser(User obj) {return this.userRepository.saveAndFlush(obj);}
  
      @Override
      public List&lt;User&gt; getAll() {
          return userRepository.findAll();
      }
  </code></pre>
  
  <p>Finally I'm trying to present as the data as well as insert something into database.</p>
  
  <pre><code>@Controller
  public class HomePageController {
  
  
      @Autowired
      private UserService userService;
  
      private static final String USER_MAP_KEY = "groups";
      private static final String USER_LIST_TEMPLATE_NAME = "groupList";
  
      @RequestMapping("/")
      String hello(Map&lt;String, Object&gt; model) {
          User osoba = new User();
          osoba.setGmail("ADAMWEST");
          userService.addUser(osoba);
  
          List&lt;User&gt; userGroupsList = userService.getAll();
          model.put(USER_MAP_KEY, userGroupsList);
          return USER_LIST_TEMPLATE_NAME;
      }
  
  }
  </code></pre>
  
  <p>If I leave out the <code>userService.addUser(osoba);</code> line, everything works fine. I can see the data read from the database neatly laid out. But when I try to actually use the <code>.addUser()</code> method my localhost puts out a white label error page.</p>
  
  <p>White label Error Page</p>
  
  <blockquote>
    <p>This application has no explicit mapping for /error, so you are seeing this as a fallback.
    Sun Apr 19 09:36:52 CEST 2015
    There was an unexpected error (type=Internal Server Error, status=500).
    could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement</p>
  </blockquote>
  
  <p>Would you kindly tell me what is it that I'm doing wrong? I've been trying to solve the problem for some time now, and thoroughly lost hope.</p>
  
  <p>Here is the stack trace of the exception. The error concerns field 'UID' not having a default value, but I marked it as an @Id field. I also dropped the entire database and set it up again, seeing as it helped someone with a similar problem.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>java.sql.SQLException: Field 'UID' doesn't have a default value
          at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
          at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
          at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
          at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
          at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
          at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2141)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2077)
          at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2062)
          at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
          at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
          at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
          at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
          at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
          at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
          at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
          at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
          at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
          at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:324)
          at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:
  288)
          at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:194)
          at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125
  )
          at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.jav
  a:84)
          at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:2
  06)
          at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
          at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
          at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
          at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
          at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
          at org.hibernate.jpa.spi.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:1181)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(Extend
  edEntityManagerCreator.java:344)
          at com.sun.proxy.$Proxy78.persist(Unknown Source)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEnti
  tyManagerCreator.java:291)
          at com.sun.proxy.$Proxy78.persist(Unknown Source)
          at org.springframework.data.jpa.repository.support.SimpleJpaRepository.save(SimpleJpaRepository.java:407)
          at org.springframework.data.jpa.repository.support.SimpleJpaRepository.saveAndFlush(SimpleJpaRepository.java:421
  )
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.exec
  uteMethodOn(RepositoryFactorySupport.java:416)
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doIn
  voke(RepositoryFactorySupport.java:401)
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invo
  ke(RepositoryFactorySupport.java:373)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.data.repository.core.support.RepositoryFactorySupport$DefaultMethodInvokingMethodIntercep
  tor.invoke(RepositoryFactorySupport.java:486)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterce
  ptor.java:99)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspec
  tSupport.java:281)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTransla
  tionInterceptor.java:136)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingM
  ethodIntercceptor.invoke(CrudMethodMetadataPostProcessor.java:122)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
          at com.sun.proxy.$Proxy80.saveAndFlush(Unknown Source)
          at put.io.come_together.service.persistance.impl.UserServiceImpl.addUser(UserServiceImpl.java:26)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:
  190)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
          at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterce
  ptor.java:99)
          at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspec
  tSupport.java:281)
          at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
          at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
          at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
          at com.sun.proxy.$Proxy83.addUser(Unknown Source)
          at put.io.come_together.controller.HomePageController.hello(HomePageController.java:29)
          at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
          at java.lang.reflect.Method.invoke(Method.java:497)
          at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
          at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:13
  7)
          at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletIn
  vocableHandlerMethod.java:110)
          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(Request
  MappingHandlerAdapter.java:777)
          at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMapp
  ingHandlerAdapter.java:706)
          at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.j
  ava:85)
          at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:943)
          at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:877)
          at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:966)
          at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:857)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:618)
          at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)
          at javax.servlet.http.HttpServlet.service(HttpServlet.java:725)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:291)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
          at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
          at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
          at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
          at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:219)
          at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
          at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
          at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:142)
          at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
          at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
          at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:516)
          at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1086)
          at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:659)
          at org.apache.coyote.http11.Http11NioProtocol$Http11ConnectionHandler.process(Http11NioProtocol.java:223)
          at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1558)
          at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1515)
          at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
          at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
          at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
          at java.lang.Thread.run(Thread.java:745)</code></pre>
  </div>
  </div>
  </p>