title: Hibernate. Saving Object with foreign keys to DB. MySQLIntegrityConstraintViolationException: Column cannot be null
body: <p>On saving new object to <code>Users</code> table I have <strong>MySQLIntegrityConstraintViolationException</strong> on this method call. </p>
  
  <pre><code>sessionFactory.getCurrentSession.save(newUser);
  </code></pre>
  
  <p><strong>Stack trace:</strong></p>
  
  <pre><code>
  org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute statement
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:973)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
  
  root cause
  
  org.hibernate.exception.ConstraintViolationException: could not execute statement
      org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:74)
      org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
      org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
      org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:136)
      org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
      org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2975)
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3487)
      org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
      org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
      org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:214)
      org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
      org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:178)
      org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
      org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
      org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
      org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
      org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
      org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
      org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
      org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
      org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
      com.petrez.model.dao.GenericDaoImpl.put(GenericDaoImpl.java:28)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy30.put(Unknown Source)
      com.petrez.service.RegistrationServiceImpl.registerUser(RegistrationServiceImpl.java:21)
      com.petrez.controller.Index.processRegistration(Index.java:36)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
  
  root cause
  
  com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Column 'roleId' cannot be null
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      com.mysql.jdbc.Util.handleNewInstance(Util.java:411)
      com.mysql.jdbc.Util.getInstance(Util.java:386)
      com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1041)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4190)
      com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4122)
      com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2570)
      com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2731)
      com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2818)
      com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2157)
      com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2460)
      com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2377)
      com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2361)
      org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:133)
      org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
      org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2975)
      org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3487)
      org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
      org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:377)
      org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:214)
      org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:194)
      org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:178)
      org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:321)
      org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:286)
      org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:192)
      org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:206)
      org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:55)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:191)
      org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:49)
      org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90)
      org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:764)
      org.hibernate.internal.SessionImpl.save(SessionImpl.java:756)
      org.hibernate.internal.SessionImpl.save(SessionImpl.java:752)
      com.petrez.model.dao.GenericDaoImpl.put(GenericDaoImpl.java:28)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
      org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
      com.sun.proxy.$Proxy30.put(Unknown Source)
      com.petrez.service.RegistrationServiceImpl.registerUser(RegistrationServiceImpl.java:21)
      com.petrez.controller.Index.processRegistration(Index.java:36)
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
      java.lang.reflect.Method.invoke(Method.java:601)
      org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:214)
      org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
      org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)
      org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)
      org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)
      org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)
      org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)
      org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)
      org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
      org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
      org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.rememberme.RememberMeAuthenticationFilter.doFilter(RememberMeAuthenticationFilter.java:146)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
      org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
      org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
      org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
      org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
      org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
      org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
  </code></pre>
  
  <p>I have 3 Tables in MySQL. <code>Users</code>, <code>Roles</code>, <code>Accounts</code>.</p>
  
  <p><code>Users</code> table has foreign key to <code>Roles</code> : <code>User.roleId -&gt; Roles.roleId</code> <strong>One To Many</strong>. Primary key <code>userId</code>. </p>
  
  <p><code>Accounts</code> table has foreign key to <code>Users</code> : <code>Accounts.accountId -&gt; Users.userId</code> <strong>One To One</strong>. Primary key <code>accountId</code></p>
  
  <p><strong>Ccreating new User object</strong></p>
  
  <pre><code>@Override
      public void registerUser(Registration reg) {
          User newUser = new User();
          newUser.setUsername(reg.getEmail());
          newUser.setPassword(reg.getPassword());
  
          genericDao.put(newUser);
          Integer userId = genericDao.getByName(User.class, "username", reg.getEmail()).get(0).getUserId();
          genericDao.put(new Account(userId));
      }
  </code></pre>
  
  <p>I have Exception on <code>genericDao.put(newUser);</code> method invoke. Inside this method is only <code>sessionFactory.getCurrentSession().save(obj);</code> <code>Role</code> object I don't create. So <code>User.account</code> and <code>User.role</code> are NULL. Also in MySQL default value configured. </p>
  
  <p><strong>User.java</strong></p>
  
  <pre><code>
  @Entity
  @SuppressWarnings("unused")
  @Table(name = "Users", uniqueConstraints = @UniqueConstraint(columnNames = "username"))
  public class User implements Serializable, UserDetails{
  
      private static final long serialVersionUID = 6475100100480917262L;
  
      @Id
      @Column(name = "userId", length = 10)
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private Integer userId;
  
      @JoinColumn(name = "roleId", nullable = true, updatable = false)
      @ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.REMOVE)
      private Role role;
  
      @OneToOne(mappedBy = "user", fetch = FetchType.LAZY, cascade = CascadeType.REMOVE)
      private Account account;
  
      @Column(name = "username", length = 30)
      private String username;
  
      @Column(name = "password", length = 45)
      private String password;
  
      @Column(name = "nonExpired")
      private boolean accountNonExpired;
  
      @Column(name = "nonLocked")
      private boolean accountNonLocked;
  
      @Column(name = "credentialsNonExpired")
      private boolean credentialsNonExpired;
  
      @Column(name = "enabled")
      private boolean enabled;
  
      //Getter and setters
  }
  </code></pre>
  
  <p><strong>Role.java</strong></p>
  
  <pre><code>
  @Entity
  @SuppressWarnings("unused")
  @Table(name = "Roles")
  public class Role implements Serializable, GrantedAuthority, Cloneable {
  
      private static final long serialVersionUID = 3586090230433600805L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "roleId", length = 10, unique = true, nullable = false)
      private Integer roleId;
  
  
      @Column(name = "role", length = 45, unique = true, nullable = true)
      private String  role;
  
      @OneToMany(cascade = CascadeType.REMOVE, fetch = FetchType.EAGER, mappedBy = "role")
      private Set usetSet = new HashSet(0);
  
      //Getters and setters
  }
  </code></pre>
  
  <p><strong>Account.java</strong></p>
  
  <pre><code>
  @Entity
  @Table(name = "Accounts")
  @SuppressWarnings("unused")
  public class Account implements Serializable {
  
      private static final long serialVersionUID = -7045300306954075788L;
  
      @Id
      @GenericGenerator(name = "generator", strategy = "foreign",
          parameters = @Parameter(name = "property", value = "user"))
      @GeneratedValue(generator = "generator")
      @Column(name = "accountId", length = 10, nullable = false)
      private Integer accountId;
  
      @Column(name = "firstName", length = 45, nullable = true)
      private String firstName;
  
      @Column(name = "lastName", length = 45, nullable = true)
      private String lastName;
  
      @Column(name = "gender", nullable = true)
      private Boolean gender;
  
      @Temporal(TemporalType.DATE)
      @Column(name = "birthDate", nullable = true)
      private Date birthDate;
  
      @Column(name = "profilePhoto", length = 250, nullable = false)
      private String profilePhoto;
  
      @PrimaryKeyJoinColumn
      @OneToOne(fetch = FetchType.EAGER, cascade = CascadeType.REFRESH)
      private User user;
  
      //Getters and setters
  }
  </code></pre>
  
  <p>Everywhere for this classes I'm using default constructors.</p>