3

I'm getting the following error when invoking the Spring Data JPA save() method:

-- UPDATED WITH SQL LOGGING --

[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) select role0_.RLE_ID as RLE1_0_, role0_.RLE_ROLE as RLE2_0_, role0_.TENANT_ENT_ID as TENANT3_0_ from roles role0_
Hibernate: select role0_.RLE_ID as RLE1_0_, role0_.RLE_ROLE as RLE2_0_, role0_.TENANT_ENT_ID as TENANT3_0_ from roles role0_
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [Enterprise Manager] as column [RLE2_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_0_]
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) select permission0_.RLE_ID as RLE1_0_1_, permission0_.PRM_ID as PRM2_1_, permission1_.PRM_ID as PRM1_7_0_, permission1_.PRM_PERMISSION as PRM2_7_0_, permission1_.TENANT_ENT_ID as TENANT3_7_0_ from ROLE_PERMISSIONS permission0_ inner join permissions permission1_ on permission0_.PRM_ID=permission1_.PRM_ID where permission0_.RLE_ID=?
Hibernate: select permission0_.RLE_ID as RLE1_0_1_, permission0_.PRM_ID as PRM2_1_, permission1_.PRM_ID as PRM1_7_0_, permission1_.PRM_PERMISSION as PRM2_7_0_, permission1_.TENANT_ENT_ID as TENANT3_7_0_ from ROLE_PERMISSIONS permission0_ inner join permissions permission1_ on permission0_.PRM_ID=permission1_.PRM_ID where permission0_.RLE_ID=?
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [INTEGER] - 1
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [PRM1_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [ACCESS_ENTERPRISE_DASHBOARD] as column [PRM2_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [PRM2_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [2] as column [PRM1_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [ACCESS_WORKSHOP_DASHBOARD] as column [PRM2_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [2] as column [PRM2_1_]
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) select contact0_.CON_ID as CON1_1_, contact0_.CON_FIRST_NAME as CON2_1_, contact0_.CON_LAST_NAME as CON3_1_, contact0_.CON_MIDDLE_NAME as CON4_1_, contact0_.CON_PASSWORD as CON5_1_, contact0_.TENANT_ENT_ID as TENANT6_1_, contact0_.CON_USERNAME as CON7_1_ from contacts contact0_ where contact0_.CON_USERNAME=? limit ?
Hibernate: select contact0_.CON_ID as CON1_1_, contact0_.CON_FIRST_NAME as CON2_1_, contact0_.CON_LAST_NAME as CON3_1_, contact0_.CON_MIDDLE_NAME as CON4_1_, contact0_.CON_PASSWORD as CON5_1_, contact0_.TENANT_ENT_ID as TENANT6_1_, contact0_.CON_USERNAME as CON7_1_ from contacts contact0_ where contact0_.CON_USERNAME=? limit ?
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [VARCHAR] - peter
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) select role0_.RLE_ID as RLE1_0_, role0_.RLE_ROLE as RLE2_0_, role0_.TENANT_ENT_ID as TENANT3_0_ from roles role0_ where role0_.RLE_ID=? limit ?
Hibernate: select role0_.RLE_ID as RLE1_0_, role0_.RLE_ROLE as RLE2_0_, role0_.TENANT_ENT_ID as TENANT3_0_ from roles role0_ where role0_.RLE_ID=? limit ?
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [INTEGER] - 1
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [Enterprise Manager] as column [RLE2_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_0_]
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) select permission0_.RLE_ID as RLE1_0_1_, permission0_.PRM_ID as PRM2_1_, permission1_.PRM_ID as PRM1_7_0_, permission1_.PRM_PERMISSION as PRM2_7_0_, permission1_.TENANT_ENT_ID as TENANT3_7_0_ from ROLE_PERMISSIONS permission0_ inner join permissions permission1_ on permission0_.PRM_ID=permission1_.PRM_ID where permission0_.RLE_ID=?
Hibernate: select permission0_.RLE_ID as RLE1_0_1_, permission0_.PRM_ID as PRM2_1_, permission1_.PRM_ID as PRM1_7_0_, permission1_.PRM_PERMISSION as PRM2_7_0_, permission1_.TENANT_ENT_ID as TENANT3_7_0_ from ROLE_PERMISSIONS permission0_ inner join permissions permission1_ on permission0_.PRM_ID=permission1_.PRM_ID where permission0_.RLE_ID=?
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [INTEGER] - 1
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [PRM1_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [ACCESS_ENTERPRISE_DASHBOARD] as column [PRM2_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [PRM2_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [2] as column [PRM1_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [ACCESS_WORKSHOP_DASHBOARD] as column [PRM2_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [TENANT3_7_0_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [1] as column [RLE1_0_1_]
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicExtractor.java:extract:70) found [2] as column [PRM2_1_]
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) insert into contacts (CON_FIRST_NAME, CON_LAST_NAME, CON_MIDDLE_NAME, CON_PASSWORD, TENANT_ENT_ID, CON_USERNAME) values (?, ?, ?, ?, ?, ?)
Hibernate: insert into contacts (CON_FIRST_NAME, CON_LAST_NAME, CON_MIDDLE_NAME, CON_PASSWORD, TENANT_ENT_ID, CON_USERNAME) values (?, ?, ?, ?, ?, ?)
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [VARCHAR] - Peter
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [2] as [VARCHAR] - Parker
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [3] as [VARCHAR] - 
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [4] as [VARCHAR] - $2a$10$leropYevLndPWXSgdCU.huXoWXeXA5VPnRqABBLRcYjXTVH.IH.Q.
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [5] as [INTEGER] - 1
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [6] as [VARCHAR] - peter
[DEBUG] [http-nio-8090-exec-4 01:33:59] (SQLStatementLogger.java:logStatement:111) insert into USER_ROLES (USER_CON_ID, RLE_ID) values (?, ?)
Hibernate: insert into USER_ROLES (USER_CON_ID, RLE_ID) values (?, ?)
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [1] as [INTEGER] - 10
[TRACE] [http-nio-8090-exec-4 01:33:59] (BasicBinder.java:bind:82) binding parameter [2] as [INTEGER] - 1
[ERROR] [http-nio-8090-exec-4 01:33:59] (JDBCExceptionReporter.java:logExceptions:234) Field 'TENANT_ENT_ID' doesn't have a default value
Apr 28, 2015 1:33:59 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [dispatcher] in context with path [/hub] threw exception [Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: Could not execute JDBC batch update; nested exception is org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update] with root cause
java.sql.SQLException: Field 'TENANT_ENT_ID' doesn't have a default value
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1073)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3597)
    at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3529)
    at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1990)
    at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2151)
    at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2625)
    at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2119)
    at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2415)
    at com.mysql.jdbc.PreparedStatement.executeBatchSerially(PreparedStatement.java:1976)
    at com.mysql.jdbc.PreparedStatement.executeBatch(PreparedStatement.java:1449)
    at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeBatch(NewProxyPreparedStatement.java:1723)
    at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70)
    at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:268)
    at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:188)
    at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321)
    at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51)
    at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1216)
    at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:383)
    at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:133)
    at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76)
    at org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:757)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:726)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:521)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:291)
    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(PersistenceExceptionTranslationInterceptor.java:136)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
    at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodIntercceptor.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.$Proxy53.save(Unknown Source)
    at com.motodoc.hub.service.UserServiceImpl.addUser(UserServiceImpl.java:74)
    at com.motodoc.hub.controller.administration.users.UserListController.addSave(UserListController.java:204)
    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:483)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:137)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:777)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:706)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java: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.doPost(FrameworkServlet.java:868)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:644)
    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.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.csrf.CsrfFilter.doFilterInternal(CsrfFilter.java:105)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:344)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:261)
    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.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:610)
    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)

Here is my service method which invokes the save() method:

@Override
public Contact addUser(UserForm userForm) {

    String encodedPassword;
    Contact user = userForm.getUser();

    //encode the password
    encodedPassword = encoder.encode(userForm.getPassword());

    //set the encoded password as the password
    user.setPassword(encodedPassword);

    Set<Role> securityRoles = new HashSet<Role>();

    //get Role
    securityRoles.add(roleDao.findById(userForm.getRoleId()));

    user.setRoles(securityRoles);

    user.setTenantId(securityAccessor.getCurrentLoggedUser().getTenantId());

    //now save
    return contactDao.save(user);
}

I have done the checks to make sure that the 'user' object properties (i.e. firstName, lastName, tenantId) are populated and can confirm that they are.

Any help will be much appreciated.

Here are the remaining relevant codes....

Contact Class:

@Entity
@Table(name = "contacts")
public class Contact implements UserDetails {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name="CON_ID")
    private int id;

    @NotEmpty
    @Column(name="CON_USERNAME")
    private String username;

    //Custom validation is carried out in controller class
    @Column(name="CON_PASSWORD")
    private String password;

    @NotEmpty
    @Column(name="CON_FIRST_NAME")
    private String firstName;

    @Column(name="CON_MIDDLE_NAME")
    private String middleName;

    @NotEmpty
    @Column(name="CON_LAST_NAME")
    private String lastName;

    @OneToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "USER_ROLES", joinColumns = { 
            @JoinColumn(name = "USER_CON_ID") }, inverseJoinColumns = { 
            @JoinColumn(name = "RLE_ID") })
    private Set<Role> roles;


    @Column(name = "TENANT_ENT_ID")
    private int tenantId;

//  @Column(name="ENT_ID")
//  private int enterpriseId;

    @Transient
    private final String PERMISSION_PREFIX = "ROLE_PERM_";

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        Set<GrantedAuthorityImpl> authorities = new HashSet<GrantedAuthorityImpl>();
        for (Role role : roles) {
            for (Permission permission : role.getPermissions()) {
                GrantedAuthorityImpl authority = new GrantedAuthorityImpl(PERMISSION_PREFIX + permission.getPermission());
                authorities.add(authority);
            }
        }
        return authorities;
    }

    @Override
    public boolean isAccountNonExpired() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isAccountNonLocked() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean isEnabled() {
        // TODO Auto-generated method stub
        return true;
    }


    public String getPERMISSION_PREFIX() {
        return PERMISSION_PREFIX;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }   

    //custom method
    public boolean hasPermission(String permission) {

        for (Role role : this.roles) {
            for (Permission securityPermission : role.getPermissions()) {
                if (securityPermission.getPermission().equals(permission))
                    return true;
            }
        }

        return false;
    }

    //custom method for testing - to rmeove
    public boolean hasRole(String rle) {

        for (Role role : this.roles) {
            if (role.getRole().equals(rle))
                return true;
        }

        return false;
    }

    public int getTenantId() {
        return tenantId;
    }

    public void setTenantId(int tenantId) {
        this.tenantId = tenantId;
    }
}

The DAO class:

public interface IContactDao extends JpaRepository<Contact, Long>, QueryDslPredicateExecutor<Contact> {

    public Contact findOne(Predicate predicate);

    public Contact findById(int id);

    public Page<Contact> findAll(Predicate predicate, Pageable pageable);

    public Page<Contact> findAll(Pageable pageable);

    @SuppressWarnings("unchecked")
    public Contact save(Contact contact);   
}

The persistence.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence" version="1.0">
    <persistence-unit name="hibernatePersistenceUnit" transaction-type="RESOURCE_LOCAL">
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update" />
            <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect" />
        </properties>
        <!-- <mapping-file>META-INF/orm.xml</mapping-file>  -->
    </persistence-unit>
</persistence>

Image of Mysql 'contacts' table to show the TENANT_ENT_ID column:

enter image description here

Zahanghir
  • 547
  • 4
  • 9
  • 22
  • Can you turn on SQL logging to see what goes into db? – Predrag Maric Apr 28 '15 at 12:07
  • 2
    Why are you defining a `save(Contact contact)` method in your repository when there is `save(S entity)` [from](http://docs.spring.io/spring-data/data-commons/docs/current/api/org/springframework/data/repository/CrudRepository.html?is-external=true#save-S-) `CrudRepository`? Also, from your screenshot it looks as if `TENANT_ENT_ID` is a foreign key in your actual database but not mapped as such on your entity? – Donovan Muller Apr 28 '15 at 12:25
  • @PredragMaric I have updated my question with SQL logging – Zahanghir Apr 28 '15 at 12:44
  • @DonovanMuller I have removed the save() method from the repository. TENANT_ENT_ID is not a foreign key hence no such mapping on the entity. Anyways, I have run the application and still getting same issue. – Zahanghir Apr 28 '15 at 13:29
  • Any chance you could put a little test project up on GitHub etc.? – Donovan Muller Apr 28 '15 at 13:31

7 Answers7

7

In my case, the problem was that the primary key column was not set as AUTO_INCREMENT

Here's how I solved it:

alter table department modify column id int NOT NULL AUTO_INCREMENT;

Ahmed Tawila
  • 988
  • 2
  • 13
  • 20
5

I just experienced the same problem and in my case the problem was that I had marked one of the properties in my entity with @NotNull annotation and had not provided any default value for it. so dropping the table, removing the annotaion and then constructing the table without the notNull constraint made everything work fine for me. Either dropping the table and rebuilding it without the NN (notNull) constraint or providing a default value for TANENT_ENT_ID (I don't know how... look it up in google) will solve your problem.

Pedram Esmaeeli
  • 174
  • 2
  • 11
  • 1
    Agree. The same can be achieved with less effort: For any rapid changes in the class annotatated as @Entity change the hibernate.hbm2ddl.auto=create this drops and recreates the table (including data) in DB. If everything works, then switch backed to hibernate.hbm2ddl.auto=update – Bechyňák Petr Oct 14 '16 at 08:14
1

In my case setting id field in database as auto_increment solved the problem.

Selim Ok
  • 1,141
  • 1
  • 7
  • 21
0

For me, the issue was, I had an extra id field in the table which cannot be null. Silly mistake.

biniam
  • 8,099
  • 9
  • 49
  • 58
0

alter table table_name modify column Column_id int primary key AUTO_INCREMENT ;

In This case If you are adding and AUTO_INCREMENT you have to apply Any one key like PK,Notnull,etc... to solve this problem...

Ziyad
  • 1
  • 3
0

I solve it by changing entity's GenerationType from 'IDENTITY' into 'AUTO' and in the database, I change my_Field into 'AUTOINCREMENT' property.

Chamod Pathirana
  • 713
  • 8
  • 16
0

Update attribute **columnDefinition = "int default 1"** in @Column with default value 1.

@Column(name = "TENANT_ENT_ID", nullable = false, columnDefinition = "int default 1")
private int tenantId;

Another configuration using xx.hbm.xml.

Mention both parent and child column default value as 1.

First you need to drop both child and parent tables. Then restart server(Tomcat).

SELECT * FROM `child`;
SELECT * FROM `parent`;

parent.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping 
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" 
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.data.Parent" table="PARENT">
        <id name="parentId" type="long">
            <column name="parentId" default="1"></column>
            <generator class="increment"></generator>
        </id>

    <property name="userId" not-null="true">
        <column name="userId" />
    </property>
    <property name="type" not-null="true" unique="true">
        <column name="type" />
    </property>
</class>

child.hbm.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping 
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" 
    "http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">

<hibernate-mapping>
    <class name="com.data.Child" table="CHILD">
        <id name="childId">
            <column name="childId" default="1"></column>
            <generator class="increment"></generator>
        </id>

    <property name="parentId" column="parentId" />

    <property name="description" not-null="true">
        <column name="description" />
    </property>
</class>

UdayKiran Pulipati
  • 6,579
  • 7
  • 67
  • 92