问:
Track by $index with pagination
I use $index to retrieve item for editing, it works fine on first page, but on 2nd, 3rd and so on indexes start from zero again.
This is my ngRepeat loop

```<code><div class="row comment-table" ng-repeat="item in items ">
</code>```

and this is at the bottom of my view where pagination is

```<code><div>
    <ul ng-if="pager.pages.length" class="pagination">
        <li ng-class="{disabled:pager.currentPage === 1}">
            <a ng-click="setPage(1)">First</a>
        </li>
        <li ng-class="{disabled:pager.currentPage === 1}">
            <a ng-click="setPage(pager.currentPage - 1)">Previous</a>
        </li>
        <li ng-repeat="page in pager.pages" ng-class="{active:pager.currentPage === page}">
            <a ng-click="setPage(page)">{{page}}</a>
        </li>
        <li ng-class="{disabled:pager.currentPage === pager.totalPages}">
            <a ng-click="setPage(pager.currentPage + 1)">Next</a>
        </li>
        <li ng-class="{disabled:pager.currentPage === pager.totalPages}">
            <a ng-click="setPage(pager.totalPages)">Last</a>
        </li>
    </ul>
    </div>
</code>```

I think I should use track in my ng-repeat but there's no use if I track by index. I tried tracking by item.id but that doesn't seem to be the case either. I read about filter: but I didn't really get how to use it.  Do I add clas or function after it or use model name? Does anyone have some examples or have idea what I do wrong?

答:
I think you are looking to get the row index of the paginated table. If so you can use the below code:

```<code>$scope.rowIndex=(currentPage-1)*pageSize +$index+1;
</code>```

where currentPage is the page you are on now, pageSize is the no. of items per page and $index is the index value of the row for that page.

Title: Track by $index with pagination

Body:
I use $index to retrieve item for editing, it works fine on first page, but on 2nd, 3rd and so on indexes start from zero again.
This is my ngRepeat loop

and this is at the bottom of my view where pagination is

            First

            Previous

            {{page}}

            Next

            Last

I think I should use track in my ng-repeat but there's no use if I track by index. I tried tracking by item.id but that doesn't seem to be the case either. I read about filter: but I didn't really get how to use it.  Do I add clas or function after it or use model name? Does anyone have some examples or have idea what I do wrong?

Body:
I think you are looking to get the row index of the paginated table. If so you can use the below code:

$scope.rowIndex=(currentPage-1)*pageSize +$index+1;

where currentPage is the page you are on now, pageSize is the no. of items per page and $index is the index value of the row for that page.


来源: stackexchange

问:
HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
Hi In my spring mvc hibernate annotation  application,i have 3 tables Employee,Team,Platform.I am using dropdown box to select the team name in Platform.jsp and Employee.jsp.When i try to delete the team without deleting the reference of corresponding references from employee table and platform table i am getting the following error.

```<code>HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query`
</code>```

Stack Trace

```<code>type Exception report

message Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`employee`, CONSTRAINT `FK4AFD4ACE1BA063F9` FOREIGN KEY (`teamId`) REFERENCES `team` (`teamId`))
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</code>```

My database
Employee table

```<code>CREATE TABLE `Employee` (  `empId` int(11) NOT NULL,
 `empName` varchar(255) DEFAULT NULL,  `empExp` int(11) NOT NULL,
 `empTeam`      varchar(255) DEFAULT NULL, `teamId` int(11) DEFAULT NULL,
  PRIMARY KEY (`empId`)),KEY `FK21` (`teamId`),
CONSTRAINT `FK21` FOREIGN KEY (`teamId`) REFERENCES `Team` (`teamId`));
</code>```

Team table

```<code> CREATE TABLE `Team` (  `teamId` int(11) NOT NULL,
    `teamName` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`teamId`));
</code>```

Platform table

```<code>CREATE TABLE `Platform` (  `pId` int(11) NOT NULL,
  `Pname` varchar(255) DEFAULT NULL,`teamId` int(11) DEFAULT NULL,
PRIMARY KEY (`pId`),KEY `FK22` (`teamId`),  CONSTRAINT `FK22` FOREIGN KEY (`teamId`) REFERENCES `Team` (`teamId`));
</code>```

Resource.java

```<code>@Entity
@Table(name="Employee")
public class Resource implements Serializable {

    private static final long serialVersionUID = -723583058586873479L;

    @Id
    @Column(name="empid")
    private Integer empId;

    @Column(name="empname")
    private String empName;

    @Column(name="empexp")
    private Integer empExp;

    @Column(name="empteam")
    private String empTeam;

      @ManyToOne(cascade = CascadeType.ALL)
     @JoinColumn(name="teamId")
     private AddTeam teams;

    public Integer getEmpId(){
        return empId;
    }
    public void setEmpId(Integer empId){
        this.empId=empId;
    }

    public String getEmpName(){
        return empName;
    }
    public void setEmpName(String empName){
        this.empName=empName;
    }

    public Integer getEmpExp(){
        return empExp;
    }
    public void setEmpExp(Integer empExp){
        this.empExp=empExp;
    }

    public String getEmpTeam(){
        return empTeam;
    }
    public void setEmpTeam(String empTeam){
        this.empTeam=empTeam;
    }

    public AddTeam getTeams() {
          return teams;
         }

         public void setTeams(AddTeam teams) {
          this.teams = teams;
         }

}
</code>```

AddTeam.java

```<code>@Entity
@Table(name="Team")

public class AddTeam {

    @Id
    @Column(name="teamId")

    private Integer teamId;

    @Column(name="teamName")
    private String teamName;

    public Integer getTeamId() {
          return teamId;
         }

         public void setTeamId(Integer teamId) {
          this.teamId = teamId;
         }

         public String getTeamName() {
          return teamName;
         }

         public void setTeamName(String teamName) {
          this.teamName = teamName;
         }
              }
</code>```

Device.java

```<code>@Entity
@Table(name="Platform")
public class Device implements Serializable{

    private static final long serialVersionUID = -723583058586873479L;
    @Id
    @Column(name="pId")
    private Integer pId;

    @Column(name="Pname")
    private String pname;

     @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="teamId")
    private AddTeam teams;

    public Integer getpId(){
        return pId;
    }
    public void setpId(Integer pId){
        this.pId=pId;
    }

    public String getpname(){
        return pname;
    }
    public void setpname(String pname){
        this.pname=pname;
    }

    public AddTeam getTeams(){
        return teams;
    }
    public void setTeams(AddTeam teams){
        this.teams=teams;
    }
}
</code>```

and this is the query used in ResourceDaoImpl.java

```<code>@Override
    public void deleteResource(int resourceid) {
        // TODO Auto-generated method stub
        sessionfactory.getCurrentSession().createQuery("DELETE FROM Resource WHERE empid=" +resourceid).executeUpdate();

        }
</code>```

Query used to delete in AddTeamDaoImpl.java

```<code>@Override
    public void deleteTeams(int teamid) {
        // TODO Auto-generated method stub
        sessiofactory.getCurrentSession().createQuery("DELETE FROM AddTeam WHERE teamid="+teamid).executeUpdate();

    }
</code>```

Query used to delete DeviceDaoImpl.java

```<code>type Exception report

message Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`employee`, CONSTRAINT `FK4AFD4ACE1BA063F9` FOREIGN KEY (`teamId`) REFERENCES `team` (`teamId`))
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</code>```0

deletefunction in ResourceController.java

```<code>type Exception report

message Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`employee`, CONSTRAINT `FK4AFD4ACE1BA063F9` FOREIGN KEY (`teamId`) REFERENCES `team` (`teamId`))
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</code>```1

delete function in DeviceController.java

```<code>type Exception report

message Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`employee`, CONSTRAINT `FK4AFD4ACE1BA063F9` FOREIGN KEY (`teamId`) REFERENCES `team` (`teamId`))
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
</code>```2

EmployeeTeam.jsp

```<code><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resource Manager</title>
</head>
<body>

<center>
<h2>Add Resources</h2>
<form:form method="POST" action="save.html">
<table>
  <tr>
    <td><form:label path="empId">Employee Id</form:label></td>
    <td><form:input path="empId" id="demo" value= "${resource.empId }"/></td>
  </tr>
  <tr>
    <td><form:label path="empName">Name</form:label></td>
    <td><form:input path="empName" value="${resource.empName }"/></td>
  </tr>

  <tr>
    <td><form:label path="empExp">Experience</form:label></td>
    <td><form:input path="empExp" value="${resource.empExp }"/></td>
  </tr>

   <tr>
    <td><form:label path="empTeam">Team</form:label></td>
    <td><form:input path="empTeam" value="${resource.empTeam}"/></td>
  </tr>

    <tr>
                    <td>
                        <form:label path="teams.teamId">Team Name</form:label>
                    </td>
                    <td>
                        <form:select path="teams.teamId" cssStyle="width: 150px;">
                            <option value="-1">Select a type</option>
                            <c:forEach items="${teamKey}" var="teams">
                            <option value="${teams.teamId}">${teams.teamName}</option>
                            </c:forEach>
                        </form:select>
                    </td>
                </tr>
                <tr>

   <td colspan="2"><input type="submit"value="Submit"></td>

    </tr>

 </table>
 </form:form>
<br/>

 <c:if test="${!empty resourcekey}">
    <table align="center" border="1">
        <tr>
            <th> Emp ID</th>
            <th>Emp Name</th>
            <th>Emp Exp</th>
            <th>Emp Team</th>
            <th>Emp TeamNmae</th>
            <th>Emp skills</th>
            <th>Options</th>
        </tr>

        <c:forEach items="${resourcekey}" var="resource">
            <tr>
                <td><c:out value="${resource.empId}"/></td>
                <td><c:out value="${resource.empName}"/></td>
                <td><c:out value="${resource.empExp}"/></td>
                <td><c:out value="${resource.empTeam}"/></td>
                <td><c:out value="${resource.teams.teamName}"/></td>

                <td align="center"><a href="editPublication.html?empId=${resource.empId}">Edit</a> | <a href="deleteResource.html?empId=${resource.empId}">Delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>

    <h2><a href="addTeam.html">Adding Category</a></h2>
</center>
</body>
</html>
</code>```

Team.jsp

```<code><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
      <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Emoloyee details</title>

<center>
<h2>Add Team Details</h2>
<form:form method="POST" action="Team.html">
   <table>
                <tr>
                    <td><form:label path="teamId">Team ID:</form:label></td>
                    <td><form:input path="teamId" id="demo" value="${team.teamId}"/></td>
                </tr>
                <tr>
                    <td><form:label path="teamName">Team Name:</form:label></td>
                    <td><form:input path="teamName" value="${team.teamName}"/></td>
                </tr>

                <tr>
                <tr>
                    <td> </td>
                  <td><input type="submit" value="SAVE"/></td>
                </tr>
            </table>
        </form:form>
        <br/>
  <c:if test="${!empty teamKey}">
    <table align="center" border="1">
        <tr>
            <th>Category ID</th>
            <th>Category Name</th>
            <th>Options</th>
        </tr>

        <c:forEach items="${teamKey}" var="team">
            <tr>
                <td><c:out value="${team.teamId}"/></td>
                <td><c:out value="${team.teamName}"/></td>
                <td align="center"><a href="editTeam.html?teamId=${team.teamId}">Edit</a> |
                 <a href="deleteTeam.html?teamId=${team.teamId}">Delete</a></td>
            </tr>
        </c:forEach>
    </table>
</c:if>
<h2><a href="updateresource.html">Adding Publication</a></h2>

</center>

</body>
</html>
</code>```

Platform.jsp

```<code><%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Platform</title>
</head>
<body>

<form:form method="POST" action="savedevice.html">
<table>
 <tr>
   <td><form:label path="pId">Platform Id</form:label></td>
   <td><form:input path="pId" value="${platform.pId}"/></td>
 </tr>

 <tr>
   <td><form:label path="pname">Platform Name</form:label></td>
   <td><form:input path="pname" value="${platform.pname}"/></td>
 </tr>

 <tr>
   <td><form:label path="teams.teamId">Team Name</form:label></td>
   <td><form:select path="teams.teamId" cssStyle="width: 150px;">
             <option value="-1"> select Team</option>
             <c:forEach items="${teamKey}" var="teams">
             <option value="${teams.teamId}">${teams.teamName}</option>
             </c:forEach>
       </form:select>
       </td>
 </tr>

 <tr>
   <td colspan="2"><input type="submit"value="Submit"></td>

    </tr>
</table>

</form:form>
<c:if test="${!empty platformKey }">
  <table align="center" border="1">
   <tr>
    <th>Platform Id</th>
    <th>Platform Name</th>
    <th>Team Name</th>

   </tr>

       <c:forEach items="${platformKey}" var="platform">
        <tr>
          <td><c:out value="${platform.pId }"/></td>
          <td><c:out value="${platform.pname }"/></td>
          <td><c:out value="${platform.teams.teamName}"/></td>
          <td><a href="editPlatform.html?pId=${platform.pId}">Edit</a> | <a href="deletePlatform.html?pId=${platform.pId}">Delete</a></td>

        </tr>

       </c:forEach>

  </table>

</c:if>
</body>
</html>
</code>```

Please help thanks in advance

答:
To solve this, the Parent should be deleted first:

http://www.baeldung.com/spring-dataIntegrityviolationexception

ContentLicense: CC BY-SA 3.0

Body:
Hi In my spring mvc hibernate annotation  application,i have 3 tables Employee,Team,Platform.I am using dropdown box to select the team name in Platform.jsp and Employee.jsp.When i try to delete the team without deleting the reference of corresponding references from employee table and platform table i am getting the following error.

HTTP Status 500 - Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query`

Stack Trace

type Exception report

message Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query

description The server encountered an internal error that prevented it from fulfilling this request.

exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

org.hibernate.exception.ConstraintViolationException: could not execute update query
    org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
    org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:84)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

root cause

com.mysql.jdbc.exceptions.MySQLIntegrityConstraintViolationException: Cannot delete or update a parent row: a foreign key constraint fails (`testdb`.`employee`, CONSTRAINT `FK4AFD4ACE1BA063F9` FOREIGN KEY (`teamId`) REFERENCES `team` (`teamId`))
    com.mysql.jdbc.SQLError.createSQLException(SQLError.java:931)
    com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2941)
    com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1623)
    com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1715)
    com.mysql.jdbc.Connection.execSQL(Connection.java:3249)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1268)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1541)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1455)
    com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1440)
    org.hibernate.hql.ast.exec.BasicExecutor.execute(BasicExecutor.java:75)
    org.hibernate.hql.ast.QueryTranslatorImpl.executeUpdate(QueryTranslatorImpl.java:396)
    org.hibernate.engine.query.HQLQueryPlan.performExecuteUpdate(HQLQueryPlan.java:259)
    org.hibernate.impl.SessionImpl.executeUpdate(SessionImpl.java:1141)
    org.hibernate.impl.QueryImpl.executeUpdate(QueryImpl.java:94)
    com.resource.ResourceDao.DeviceDaoImpl.deleteDevice(DeviceDaoImpl.java:39)
    com.resource.ResourceService.DeviceServiceImpl.deleteDevice(DeviceServiceImpl.java:43)
    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:307)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:108)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy21.deleteDevice(Unknown Source)
    com.resource.ResourceController.DeviceController.deleteDevice(DeviceController.java:61)
    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.bind.annotation.support.HandlerMethodInvoker.doInvokeMethod(HandlerMethodInvoker.java:710)
    org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:167)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:414)
    org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:402)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:771)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:716)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:647)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:552)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

My database
Employee table

CREATE TABLE `Employee` (  `empId` int(11) NOT NULL,
 `empName` varchar(255) DEFAULT NULL,  `empExp` int(11) NOT NULL,
 `empTeam`      varchar(255) DEFAULT NULL, `teamId` int(11) DEFAULT NULL,
  PRIMARY KEY (`empId`)),KEY `FK21` (`teamId`),
CONSTRAINT `FK21` FOREIGN KEY (`teamId`) REFERENCES `Team` (`teamId`));

Team table

 CREATE TABLE `Team` (  `teamId` int(11) NOT NULL,
    `teamName` varchar(255) DEFAULT NULL,
    PRIMARY KEY (`teamId`));

Platform table

CREATE TABLE `Platform` (  `pId` int(11) NOT NULL,
  `Pname` varchar(255) DEFAULT NULL,`teamId` int(11) DEFAULT NULL,
PRIMARY KEY (`pId`),KEY `FK22` (`teamId`),  CONSTRAINT `FK22` FOREIGN KEY (`teamId`) REFERENCES `Team` (`teamId`));

Resource.java

@Entity
@Table(name="Employee")
public class Resource implements Serializable {

    private static final long serialVersionUID = -723583058586873479L;

    @Id
    @Column(name="empid")
    private Integer empId;

    @Column(name="empname")
    private String empName;

    @Column(name="empexp")
    private Integer empExp;

    @Column(name="empteam")
    private String empTeam;

      @ManyToOne(cascade = CascadeType.ALL)
     @JoinColumn(name="teamId")
     private AddTeam teams;

    public Integer getEmpId(){
        return empId;
    }
    public void setEmpId(Integer empId){
        this.empId=empId;
    }

    public String getEmpName(){
        return empName;
    }
    public void setEmpName(String empName){
        this.empName=empName;
    }

    public Integer getEmpExp(){
        return empExp;
    }
    public void setEmpExp(Integer empExp){
        this.empExp=empExp;
    }

    public String getEmpTeam(){
        return empTeam;
    }
    public void setEmpTeam(String empTeam){
        this.empTeam=empTeam;
    }

    public AddTeam getTeams() {
          return teams;
         }

         public void setTeams(AddTeam teams) {
          this.teams = teams;
         }

}

AddTeam.java

@Entity
@Table(name="Team")

public class AddTeam {

    @Id
    @Column(name="teamId")

    private Integer teamId;

    @Column(name="teamName")
    private String teamName;

    public Integer getTeamId() {
          return teamId;
         }

         public void setTeamId(Integer teamId) {
          this.teamId = teamId;
         }

         public String getTeamName() {
          return teamName;
         }

         public void setTeamName(String teamName) {
          this.teamName = teamName;
         }
              }

Device.java

@Entity
@Table(name="Platform")
public class Device implements Serializable{

    private static final long serialVersionUID = -723583058586873479L;
    @Id
    @Column(name="pId")
    private Integer pId;

    @Column(name="Pname")
    private String pname;

     @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="teamId")
    private AddTeam teams;

    public Integer getpId(){
        return pId;
    }
    public void setpId(Integer pId){
        this.pId=pId;
    }

    public String getpname(){
        return pname;
    }
    public void setpname(String pname){
        this.pname=pname;
    }

    public AddTeam getTeams(){
        return teams;
    }
    public void setTeams(AddTeam teams){
        this.teams=teams;
    }
}

and this is the query used in ResourceDaoImpl.java

@Override
    public void deleteResource(int resourceid) {
        // TODO Auto-generated method stub
        sessionfactory.getCurrentSession().createQuery("DELETE FROM Resource WHERE empid=" +resourceid).executeUpdate();

        }

Query used to delete in AddTeamDaoImpl.java

@Override
    public void deleteTeams(int teamid) {
        // TODO Auto-generated method stub
        sessiofactory.getCurrentSession().createQuery("DELETE FROM AddTeam WHERE teamid="+teamid).executeUpdate();

    }

Query used to delete DeviceDaoImpl.java

@Override
    public void deleteDevice(int deviceid) {
        // TODO Auto-generated method stub
        sessionfactory.getCurrentSession().createQuery("DELETE FROM AddTeam WHERE teamid="+deviceid).executeUpdate();
    }

deletefunction in ResourceController.java

@RequestMapping(value="/delete",method=RequestMethod.GET)
    public ModelAndView deleteResourceDetails(@ModelAttribute("command")  Resource resource,
            BindingResult result){
        resourceServices.deleteResource(resource.getEmpId());
        Map<String, Object> model = new HashMap<String, Object>();
        model.put("resourcekey", resourceServices.listResources());
        model.put("teamKey", addteamServices.listTeams());
        return new  ModelAndView("EditTeam",model);
    }

delete function in DeviceController.java

@RequestMapping(value="/deletePlatform", method = RequestMethod.GET)
    public ModelAndView deleteDevice(@ModelAttribute("command") Device device, BindingResult result){
         deviceService.deleteDevice(device.getpId());
         Map<String, Object> model = new HashMap<String, Object>();
         model.put("platformKey", deviceService.listDevice());
         model.put("teamKey", teamservice.listTeams());
         return new ModelAndView("Device",model);
        }

EmployeeTeam.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Resource Manager</title>

Add Resources

<form:form method="POST" action="save.html">

    <form:label path="empId">Employee Id</form:label>
    <form:input path="empId" id="demo" value= "${resource.empId }"/>

    <form:label path="empName">Name</form:label>
    <form:input path="empName" value="${resource.empName }"/>

    <form:label path="empExp">Experience</form:label>
    <form:input path="empExp" value="${resource.empExp }"/>

    <form:label path="empTeam">Team</form:label>
    <form:input path="empTeam" value="${resource.empTeam}"/>

                        <form:label path="teams.teamId">Team Name</form:label>

                        <form:select path="teams.teamId" cssStyle="width: 150px;">
                            <option value="-1">Select a type</option>
                            <c:forEach items="${teamKey}" var="teams">
                            <option value="${teams.teamId}">${teams.teamName}</option>
                            </c:forEach>
                        </form:select>

   <input type="submit"value="Submit">

 </form:form>

 <c:if test="${!empty resourcekey}">

             Emp ID
            Emp Name
            Emp Exp
            Emp Team
            Emp TeamNmae
            Emp skills
            Options

        <c:forEach items="${resourcekey}" var="resource">

                <c:out value="${resource.empId}"/>
                <c:out value="${resource.empName}"/>
                <c:out value="${resource.empExp}"/>
                <c:out value="${resource.empTeam}"/>
                <c:out value="${resource.teams.teamName}"/>

                Edit | Delete

        </c:forEach>

</c:if>

Adding Category

Team.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
      <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>

    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Emoloyee details</title>

Add Team Details

<form:form method="POST" action="Team.html">

                    <form:label path="teamId">Team ID:</form:label>
                    <form:input path="teamId" id="demo" value="${team.teamId}"/>

                    <form:label path="teamName">Team Name:</form:label>
                    <form:input path="teamName" value="${team.teamName}"/>

                  <input type="submit" value="SAVE"/>

        </form:form>

  <c:if test="${!empty teamKey}">

            Category ID
            Category Name
            Options

        <c:forEach items="${teamKey}" var="team">

                <c:out value="${team.teamId}"/>
                <c:out value="${team.teamName}"/>
                Edit |
                 Delete

        </c:forEach>

</c:if>

Adding Publication

Platform.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@taglib uri="http://www.springframework.org/tags/form" prefix="form"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Platform</title>

<form:form method="POST" action="savedevice.html">

   <form:label path="pId">Platform Id</form:label>
   <form:input path="pId" value="${platform.pId}"/>

   <form:label path="pname">Platform Name</form:label>
   <form:input path="pname" value="${platform.pname}"/>

   <form:label path="teams.teamId">Team Name</form:label>
   <form:select path="teams.teamId" cssStyle="width: 150px;">
             <option value="-1"> select Team</option>
             <c:forEach items="${teamKey}" var="teams">
             <option value="${teams.teamId}">${teams.teamName}</option>
             </c:forEach>
       </form:select>

   <input type="submit"value="Submit">

</form:form>
<c:if test="${!empty platformKey }">

    Platform Id
    Platform Name
    Team Name

       <c:forEach items="${platformKey}" var="platform">

          <c:out value="${platform.pId }"/>
          <c:out value="${platform.pname }"/>
          <c:out value="${platform.teams.teamName}"/>
          Edit | Delete

       </c:forEach>

</c:if>

Please help thanks in advance


问:
How do I display todays date on SSRS report?
I want to show up Todays date as report generated date on SSRS report.

How can i do that ?

should I use any variable  ?

please help me I'm newbie to SSRS.

For example refer this image:

答:
Just simple use

```<code>=Format(today(), "dd/MM/yyyy")
</code>```

will solve your problem.

Body:
Just simple use

=Format(today(), "dd/MM/yyyy")

will solve your problem.

ContentLicense: CC BY-SA 4.0


问:
Pipelining setTimeout in node.js
I am writing a node.js console application. I have two setTimeout functions as follows.

```<code>setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
}, 2000);

setTimeout(function(){
    process.stdout.write('\n\nLet\'s play a game !!!\n\n');
}, 1000);
</code>```

What I actually intend is, the first message should come after 2 seconds. After that, the second message should appear after 1 second. But what's happening is, the second message appears after 1 second and then the first message appears. Both the functions are being called at once as they are asynchronous. Is there any way to pipeline them?

答:
setTimout() is not blocking in Javascript.  So, what you did is you scheduled two timers to run in the future.  One runs 1 second from now.  The other runs two seconds from now.  Thus, you get the behavior you observed.

You can either schedule the first one to run 2 seconds from now and then for one to go 1 second after that, you schedule it for 3 seconds from now.

```<code>setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
}, 2000);

// schedule this one to be 3 seconds from now, which will be 1 second after the prior one
// since that one fired in 2 seconds
setTimeout(function(){
    process.stdout.write('\n\nLet\'s play a game !!!\n\n');
}, 3000);
</code>```

Or, you can schedule the first one to run 2 seconds from now and then in that callback, you then schedule the next one to run 1 second from when the first one fires.

```<code>setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
        // when the first timer fires, set a new timer to run the second
        // part one second from when the first one fired
        setTimeout(function(){
            process.stdout.write('\n\nLet\'s play a game !!!\n\n');
        }, 1000);
}, 2000);
</code>```

This non-blocking characteristic is what gives Javascript it's asynchronous behavior.  When you call the first setTimeout(), the Javascript interpreter doesn't just stop and wait for the timer to fire.  Instead, it schedules that timer to run sometime in the future and then it keeps on executing the rest of your Javascript.  In your code, the next line of code is another setTimeout() so it immediately schedules that timer too.  Since they were both scheduled at the same time, it makes sense that the one scheduled for 2 seconds from now comes after the one scheduled for 1 second from now.

Thus, you end up with two choices.  You can either change the time on the second time to make it fire when you want it to fire (given that the code to schedule both timers is run at basically the same time) or you can change when you schedule the second timer until after the first timer has fired.

Title: Pipelining setTimeout in node.js

Body:
I am writing a node.js console application. I have two setTimeout functions as follows.

setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
}, 2000);

setTimeout(function(){
    process.stdout.write('\n\nLet\'s play a game !!!\n\n');
}, 1000);

What I actually intend is, the first message should come after 2 seconds. After that, the second message should appear after 1 second. But what's happening is, the second message appears after 1 second and then the first message appears. Both the functions are being called at once as they are asynchronous. Is there any way to pipeline them?

Body:
setTimout() is not blocking in Javascript.  So, what you did is you scheduled two timers to run in the future.  One runs 1 second from now.  The other runs two seconds from now.  Thus, you get the behavior you observed.

You can either schedule the first one to run 2 seconds from now and then for one to go 1 second after that, you schedule it for 3 seconds from now.

setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
}, 2000);

// schedule this one to be 3 seconds from now, which will be 1 second after the prior one
// since that one fired in 2 seconds
setTimeout(function(){
    process.stdout.write('\n\nLet\'s play a game !!!\n\n');
}, 3000);

Or, you can schedule the first one to run 2 seconds from now and then in that callback, you then schedule the next one to run 1 second from when the first one fires.

setTimeout(function(){
    process.stdout.write('\n\nJokes Apart !!!\n\n');
        // when the first timer fires, set a new timer to run the second
        // part one second from when the first one fired
        setTimeout(function(){
            process.stdout.write('\n\nLet\'s play a game !!!\n\n');
        }, 1000);
}, 2000);

This non-blocking characteristic is what gives Javascript it's asynchronous behavior.  When you call the first setTimeout(), the Javascript interpreter doesn't just stop and wait for the timer to fire.  Instead, it schedules that timer to run sometime in the future and then it keeps on executing the rest of your Javascript.  In your code, the next line of code is another setTimeout() so it immediately schedules that timer too.  Since they were both scheduled at the same time, it makes sense that the one scheduled for 2 seconds from now comes after the one scheduled for 1 second from now.

Thus, you end up with two choices.  You can either change the time on the second time to make it fire when you want it to fire (given that the code to schedule both timers is run at basically the same time) or you can change when you schedule the second timer until after the first timer has fired.


问:
jQuery Validate- throws error all time
I wrote a custom validator for jquery validator plugin .

Problem is, the custom validator I wrote is throwing error for anything I input. If I input plain text, it will still show error message.

答:
Since it's a validator your function should return false if the value matches the regex and true if not:

```<code>$.validator.addMethod('noHTMLallowed', function(value) {
  return !/<(.|\n)*?>/.test(value);
}, 'It contains HTML tags');
</code>```

Title: jQuery Validate- throws error all time

Body:
Since it's a validator your function should return false if the value matches the regex and true if not:

$.validator.addMethod('noHTMLallowed', function(value) {
  return !/<(.|\n)*?>/.test(value);
}, 'It contains HTML tags');


问:
Use of undeclared type '' Swift ERROR
My swift project suddenly stoped working. It throws up the errors:

Use of undeclared type 'GameScene'

and

Use of unresolved identifier 'GameScene'

My GameViewController file is:

```<code>class GameViewController: UIViewController {

var scene: GameScene!    //Use of undeclared type 'GameScene'

override func viewDidLoad() {
    super.viewDidLoad()

    let skView = view as! SKView
    skView.isMultipleTouchEnabled = false

    scene = GameScene(size: skView.bounds.size)    //Use of unresolved identifier 'GameScene'
    scene.scaleMode = .aspectFill

    skView.presentScene(scene)
}
</code>```

My GameScene file is:

```<code>class GameScene: SKScene {

var platform1: Platform!

override func didMove(to view: SKView) {
    scene?.backgroundColor = UIColor(red: 132.0/255.0, green: 179.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    addPlatforms()
}

func addPlatforms() {
    platform1 = Platform()
    platform1.size.width = frame.size.width / 4
    platform1.position = CGPoint(x: platform1.width / 2, y: frame.size.height / 8)
    addChild(platform1)
}
</code>```

Any help will be greatly appreciated.

答:
At the top of your file, write import SpriteKit. SpriteKit is the framework that allows you to use GameScene.

Let me know if that helps!

Title: Use of undeclared type '' Swift ERROR

Body:
My swift project suddenly stoped working. It throws up the errors:

Use of undeclared type 'GameScene'

and

Use of unresolved identifier 'GameScene'

My GameViewController file is:

class GameViewController: UIViewController {

var scene: GameScene!    //Use of undeclared type 'GameScene'

override func viewDidLoad() {
    super.viewDidLoad()

    let skView = view as! SKView
    skView.isMultipleTouchEnabled = false

    scene = GameScene(size: skView.bounds.size)    //Use of unresolved identifier 'GameScene'
    scene.scaleMode = .aspectFill

    skView.presentScene(scene)
}

My GameScene file is:

class GameScene: SKScene {

var platform1: Platform!

override func didMove(to view: SKView) {
    scene?.backgroundColor = UIColor(red: 132.0/255.0, green: 179.0/255.0, blue: 255.0/255.0, alpha: 1.0)

    addPlatforms()
}

func addPlatforms() {
    platform1 = Platform()
    platform1.size.width = frame.size.width / 4
    platform1.position = CGPoint(x: platform1.width / 2, y: frame.size.height / 8)
    addChild(platform1)
}

Any help will be greatly appreciated.


问:
Installing NodeJS on Ubuntu 16.04 Server with the Package manager installs only the distro version (v.4) instead of LTS
I have this odd problem that when I try to install NodeJS on a fresh Ubuntu Server VM.

I execute the two simple steps from the official instruction but somehow I manage to fail.

In the home directory of my user I execute curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - which ends successfully and then sudo apt-get install -y nodejs but this results in the installation of v.4.2.6.

Output can be seen below:

```<code>Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3161 kB of archives.
After this operation, 13,2 MB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 97187 files and directories currently installed.)
Preparing to unpack .../nodejs_4.2.6~dfsg-1ubuntu4.1_amd64.deb ...
Unpacking nodejs (4.2.6~dfsg-1ubuntu4.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (4.2.6~dfsg-1ubuntu4.1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode
</code>```

Please help.

答:
The answer was hiding in this thread: Installing NodeJS on Ubuntu Trusty

So it must have been some kind of an issue with curl using the local network so I used wget to download like this:

wget https://deb.nodesource.com/setup_6.x

And then from the same directory:

sudo bash ./setup_6.x

And finally:

sudo apt-get install nodejs

Which did it.

Body:
I have this odd problem that when I try to install NodeJS on a fresh Ubuntu Server VM.

I execute the two simple steps from the official instruction but somehow I manage to fail.

In the home directory of my user I execute curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash - which ends successfully and then sudo apt-get install -y nodejs but this results in the installation of v.4.2.6.

Output can be seen below:

Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed:
  nodejs
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 0 B/3161 kB of archives.
After this operation, 13,2 MB of additional disk space will be used.
Selecting previously unselected package nodejs.
(Reading database ... 97187 files and directories currently installed.)
Preparing to unpack .../nodejs_4.2.6~dfsg-1ubuntu4.1_amd64.deb ...
Unpacking nodejs (4.2.6~dfsg-1ubuntu4.1) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up nodejs (4.2.6~dfsg-1ubuntu4.1) ...
update-alternatives: using /usr/bin/nodejs to provide /usr/bin/js (js) in auto mode

Please help.


问:
File::load in drupal8 custom module controller
i have created one custom module, in the controller file i used File::load static method. but when I'm run phpcs for check coding standards it will give an error as

File::load calls should be avoided in classes, use dependency injection instead

anyone can please tell how to create dependency injection for this.

答:
The be achieved by using Drupal\Core\Entity\EntityTypeManagerInterface.

```<code>use Drupal\Core\Entity\EntityTypeManagerInterface;

class MyForm extends FormBase {

 /**
  * The storage handler class for files.
  *
  * @var \Drupal\file\FileStorage
  */
 protected $fileStorage;

 /**
  * This is an example.
  *
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity
  *   The Entity type manager service.
  */
  public function __construct(EntityTypeManagerInterface $entity) {
    $this->fileStorage = $entity->getStorage('file');
  }
  ....
 }
</code>```

From there you can update the File::load($fid) to $this->fileStorage->load($fid)

Body:
The be achieved by using Drupal\Core\Entity\EntityTypeManagerInterface.

use Drupal\Core\Entity\EntityTypeManagerInterface;

class MyForm extends FormBase {

 /**
  * The storage handler class for files.
  *
  * @var \Drupal\file\FileStorage
  */
 protected $fileStorage;

 /**
  * This is an example.
  *
  * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity
  *   The Entity type manager service.
  */
  public function __construct(EntityTypeManagerInterface $entity) {
    $this->fileStorage = $entity->getStorage('file');
  }
  ....
 }

From there you can update the File::load($fid) to $this->fileStorage->load($fid)


问:
border radius not round as expected
codepen

In above example, I have tried switch box style and i have tried in em value,when i have written font size 16px based on their parents ,according veiwport there will be changes in font size while changing  switch box circle is not perfect ,For particular font size is suitable (eg:parent font-size 20px,22px)

Here is the code

.parent {
  font-size: 16px;
  text-align: center;
  margin-top: 10px
}

.BP_swtchbox {
  display: inline-block;
  font-size: 1em
}

.BP_Swtch {
  cursor: pointer;
  background: #d7d9dd;
  border-radius: 0.313em;
  height: 0.625em;
  width: 1.500em;
  display: inline-block;
  position: relative;
  transition: .4s;
  -ms-transition: .4s;
  -moz-transition: .4s;
  -webkit-transition: .4s
}

.BP_swtchbox input {
  display: none
}

.BP_Swtbx_lb {
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px 0 #777;
  height: 0.875em;
  width: 0.875em;
  position: absolute;
  top: 0;
  left: 0;
  transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -ms-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -moz-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -webkit-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  bottom: 0;
  margin: auto
}

.BP_swtchbox input:checked+.BP_Swtch {
  box-shadow: 0 0 0 0.375em #58b14c inset
}

.BP_swtchbox input:checked+.BP_Swtch .BP_Swtbx_lb {
  left: calc(100% - 0.875em);
  left: -ms-calc(100% - 0.875em);
  left: -moz-calc(100% - 0.875em);
  left: -webkit-calc(100% - 0.875em)
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><div class="parent">
  <label class="BP_swtchbox" for="BPSwitch">
    <input type="checkbox" id="BPSwitch" class="hide">
      <label class="BP_Swtch" for="BPSwitch">
        <span class="BP_Swtbx_lb"></span>
      </label>
  </label>
</div></code>```

Here is the screenshot for  font size of 20px for parent  class.....for switch icon

What to do for that....

答:
This is very interesting. It appears that when .parent has a font-size of 20px, the width and height of .BP_Swtbx_lb (which are both expressed as 0.875em) gets calculated to 17.5 pixels. Since pixels can't be fractional they get rounded, but the weird thing here is that the height get rounded down to 17 while the width get rounded up to 18.

When .parent has a font-size of 22px, it appears to be the complete opposite, height gets rounded up and width gets rounded down. They should definitely both be unambiguously rounded down in this case since it's calculated to 19.25 pixels.

The odd shape seems to be caused by the curve being calculated from the non-rounded values rather than the rounded values. Compare the shape when setting the non-rounded values to when explicitly setting the rounded values, it's slightly rectangular in the former case and perfectly elliptical in the latter. So there's an inconsistency between the rendered curve and rendered dimensions.

This only seems to be the case in Chrome. Neither Safari nor Firefox display this behavior.

Now, it's up to the browser implementation how it rounds fractional pixels, but you'd think it would at least be internally consistent. I'm willing to conclude that this is a browser bug and it should be reported as such to the Google Chrome dev team.

Title: border radius not round as expected

Body:
codepen

In above example, I have tried switch box style and i have tried in em value,when i have written font size 16px based on their parents ,according veiwport there will be changes in font size while changing  switch box circle is not perfect ,For particular font size is suitable (eg:parent font-size 20px,22px)

Here is the code

.parent {
  font-size: 16px;
  text-align: center;
  margin-top: 10px
}

.BP_swtchbox {
  display: inline-block;
  font-size: 1em
}

.BP_Swtch {
  cursor: pointer;
  background: #d7d9dd;
  border-radius: 0.313em;
  height: 0.625em;
  width: 1.500em;
  display: inline-block;
  position: relative;
  transition: .4s;
  -ms-transition: .4s;
  -moz-transition: .4s;
  -webkit-transition: .4s
}

.BP_swtchbox input {
  display: none
}

.BP_Swtbx_lb {
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 4px 0 #777;
  height: 0.875em;
  width: 0.875em;
  position: absolute;
  top: 0;
  left: 0;
  transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -ms-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -moz-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  -webkit-transition: .3s cubic-bezier(.4, 1.3, .65, 1.1);
  bottom: 0;
  margin: auto
}

.BP_swtchbox input:checked+.BP_Swtch {
  box-shadow: 0 0 0 0.375em #58b14c inset
}

.BP_swtchbox input:checked+.BP_Swtch .BP_Swtbx_lb {
  left: calc(100% - 0.875em);
  left: -ms-calc(100% - 0.875em);
  left: -moz-calc(100% - 0.875em);
  left: -webkit-calc(100% - 0.875em)
}

    <input type="checkbox" id="BPSwitch" class="hide">

Here is the screenshot for  font size of 20px for parent  class.....for switch icon

What to do for that....


问:
How to retrieve currently logged in username in Windows?
I wish to retrieve the username of the currently logged in user in Windows (preferably some solution that works from Windows XP to W10) in a Delphi 7 project.

I tried both solutions given in this question, but they all give the name of the user, not the actual "username" that is used to log into Windows.

For example, the "username" I use to log into Windows is "joao.victor" (using a local Windows account), or my e-mail when I use a Microsoft account. But when I tried those 2 solutions, the string it returned was "João", which is my first name and the name configured in those accounts.

Does anyone know of a solution where I can retrieve the username that is used to log into Windows instead of the first name of the user?

答:
With LUA and RunAs and whatnot this is far more complicated than it seems..
But the oldest and simplest trick still works even when switching accounts.

in pre Server 2003 use:

```<code> HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersioin\Winlogon DefaultUserName
</code>```

and above:

```<code> HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI LastLoggedOnSAMUser
</code>```

LastLoggedOnSAMUser will be in format DOMAIN\USERNAME where a local domain can be a Period.

Body:
With LUA and RunAs and whatnot this is far more complicated than it seems..
But the oldest and simplest trick still works even when switching accounts.

in pre Server 2003 use:

 HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersioin\Winlogon DefaultUserName

and above:

 HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Authentication\LogonUI LastLoggedOnSAMUser

LastLoggedOnSAMUser will be in format DOMAIN\USERNAME where a local domain can be a Period.


问:
RanorexPath Attribute does not match
Problem: Attribute does not match the specified value:

Validation Failure: Attribute 'Text' of element for item 'CommonRepository.MyApp.InfoTab.StatusWaitingForNewRound' does not match the specified value (actual='Status: Waiting for start', expected='Status: Waiting for a new round').

My path for this repo item: .//text[@automationid='textGameStatus' and @text='Status:           Waiting for a new round' or @text='Status:           Waiting for start']

As you see I am using "or", hence I expect it to accept either one or another and if there are neither then it should fail, but in reality it does not work this way.

What am I doing wrong here? Thank you.

答:
If you consider 'Status: Waiting for' to be a correct value, why not just use the starts with (>) symbol:

```<code>//text[@automationid='textGameStatus' and @text>'Status: Waiting for']
</code>```

Or you could use regex (~) symbol:

```<code>//text[@automationid='textGameStatus' and @text~'Status: Waiting for.+']
</code>```

Or you could just create a repo item with //text[@automationid='textGameStatus'] and read its @text attribute then compare it to predefined list of strings (or regex in user code.

Don't forget to validate that you repo item works for all supported cases using the spy.

If you repo item is correctly mapped, it should work as expected.

Hope it helps!

Title: RanorexPath Attribute does not match

Body:
If you consider 'Status: Waiting for' to be a correct value, why not just use the starts with (>) symbol:

//text[@automationid='textGameStatus' and @text>'Status: Waiting for']

Or you could use regex (~) symbol:

//text[@automationid='textGameStatus' and @text~'Status: Waiting for.+']

Or you could just create a repo item with //text[@automationid='textGameStatus'] and read its @text attribute then compare it to predefined list of strings (or regex in user code.

Don't forget to validate that you repo item works for all supported cases using the spy.

If you repo item is correctly mapped, it should work as expected.

Hope it helps!


问:
How to combine and collect elements of an RDD into a list in pyspark
I am working with Apache Spark for python and have created an spark dataframe with name, latitude, longitude as the column names.

my RDD dataframe is in the form:

```<code>name     latitude      longitude

M          1.3           22.5
S          1.6           22.9
H          1.7           23.4
W          1.4           23.3
C          1.1           21.2
...        ...           ....
</code>```

I know that to collect only the latitude I can do

```<code>list_of_lat = df.rdd.map(lambda r: r.latitude).collect()

print list_of_lat

[1.3,1.6,1.7,1.4,1.1,...]
</code>```

However, I need to collect the latitude and longitude values together in a list in the form:

```<code>[[1.3,22.5],[1.6,22.9],[1.7,23.4]...]
</code>```

I have tried

```<code>lat_lon = df.rdd.map(lambda r,x : r.latitude, x.longitude).collect()
</code>```

however this does not work.

I need to use the spark since it is a very large dataset (~1M rows).

Any help would be greatly appreciated. Thanks

答:
I'm assuming lat_lon = df.rdd.map(lambda r,x : r.latitude, x.longitude).collect()

gave you the following error
NameError: name 'x' is not defined

try

lat_lon = df.rdd.map(lambda x : [x.latitude, x.longitude]).collect()

Body:
I am working with Apache Spark for python and have created an spark dataframe with name, latitude, longitude as the column names.

my RDD dataframe is in the form:

name     latitude      longitude

M          1.3           22.5
S          1.6           22.9
H          1.7           23.4
W          1.4           23.3
C          1.1           21.2
...        ...           ....

I know that to collect only the latitude I can do

list_of_lat = df.rdd.map(lambda r: r.latitude).collect()

print list_of_lat

[1.3,1.6,1.7,1.4,1.1,...]

However, I need to collect the latitude and longitude values together in a list in the form:

[[1.3,22.5],[1.6,22.9],[1.7,23.4]...]

I have tried

lat_lon = df.rdd.map(lambda r,x : r.latitude, x.longitude).collect()

however this does not work.

I need to use the spark since it is a very large dataset (~1M rows).

Any help would be greatly appreciated. Thanks


问:
Java adding a 2D arraylist to a list of 2D arraylists
I am creating a map system for my game which requires me at a few stages to replace the old 2D array map with another. What I wanted to do is add all the 2D arraylist maps into a List of these 2D arraylists. However, what I found difficult was that when I wanted to retrieve said map, the .get method would not give me the correct data, as it you would try to pull the first item of that arraylist which in this case would be null. Thus the program threw me nullpointerexceptions.

```<code>private int[][] mapArray;
private List<int[][]> maps = new ArrayList<>();

    mapArray = new int[][]{
    {0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 9, 1, 1, 7, 7, 7, 7, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {7, 7, 7, 7, 5, 8, 8, 8, 4, 6, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 8, 8, 8, 4, 4, 6, 7, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 8, 8, 8, 4, 4, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   };
   maps.add(mapArray);
</code>```

When I sout maps.get(0) I get the following:

```<code>[[I@58838f3f
</code>```

If I have two items, it will show up like this:

```<code>[[[I@58838f3f, [[I@59a60155]
</code>```

Ideally I want it to be added like this:

```<code>[I@58838f3f, I@58838f3f]
</code>```

I am just unsure how to do this. Any help would be appreciated!

I might have overlooked something obvious, probably is the case!

Much obliged

答:
You seem to be confusing the output of converting your map (or the list of maps) to string (which is what happens when you try to print them) - with what actual value there are there.

Because ArrayList like most Java container formats have nice toString() implementations that get automatically called when trying to print them, you'd get something that "looks like an array" in the output. So for example when printing an array list containing two strings, it might look like this: [a, b].

Arrays don't have such nice formatters, because they aren't really objects (they are "primitive types") and so print them gets you their address and some Java byte code that describes their type (if you can understand Java byte code), so an array of integers will look like this: [I@<address> while an two dimensional array of bytes will look like this: [[B@<address>, and so on.

In regards to your original question, the code seems to work well for me. Here is an example program:

```<code>import java.util.ArrayList;

public class Test2D {

    public static void main(String... args) {
        ArrayList<int[][]> maps = new ArrayList<>();
        maps.add(new int[][] {
            {1,2,3},
            {4,5,6},
            {7,8,9},
        });
        maps.add(new int[][] {
            {10,20,30},
            {40,50,60},
        });
        int[][] map = maps.get(0);
        System.out.println(map[0][0]);
    }
}
</code>```

The output will print correctly 1 , showing that there is no null pointer exception.

Body:
I am creating a map system for my game which requires me at a few stages to replace the old 2D array map with another. What I wanted to do is add all the 2D arraylist maps into a List of these 2D arraylists. However, what I found difficult was that when I wanted to retrieve said map, the .get method would not give me the correct data, as it you would try to pull the first item of that arraylist which in this case would be null. Thus the program threw me nullpointerexceptions.

private int[][] mapArray;
private List<int[][]> maps = new ArrayList<>();

    mapArray = new int[][]{
    {0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0},
    {0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {0, 1, 9, 1, 1, 7, 7, 7, 7, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {7, 7, 7, 7, 5, 8, 8, 8, 4, 6, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 8, 8, 8, 4, 4, 6, 7, 7, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
    {4, 4, 4, 4, 4, 8, 8, 8, 4, 4, 4, 4, 4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
   };
   maps.add(mapArray);

When I sout maps.get(0) I get the following:

[[I@58838f3f

If I have two items, it will show up like this:

[[[I@58838f3f, [[I@59a60155]

Ideally I want it to be added like this:

[I@58838f3f, I@58838f3f]

I am just unsure how to do this. Any help would be appreciated!

I might have overlooked something obvious, probably is the case!

Much obliged

Body:
You seem to be confusing the output of converting your map (or the list of maps) to string (which is what happens when you try to print them) - with what actual value there are there.

Because ArrayList like most Java container formats have nice toString() implementations that get automatically called when trying to print them, you'd get something that "looks like an array" in the output. So for example when printing an array list containing two strings, it might look like this: [a, b].

Arrays don't have such nice formatters, because they aren't really objects (they are "primitive types") and so print them gets you their address and some Java byte code that describes their type (if you can understand Java byte code), so an array of integers will look like this: [I@<address> while an two dimensional array of bytes will look like this: [[B@<address>, and so on.

In regards to your original question, the code seems to work well for me. Here is an example program:

import java.util.ArrayList;

public class Test2D {

    public static void main(String... args) {
        ArrayList<int[][]> maps = new ArrayList<>();
        maps.add(new int[][] {
            {1,2,3},
            {4,5,6},
            {7,8,9},
        });
        maps.add(new int[][] {
            {10,20,30},
            {40,50,60},
        });
        int[][] map = maps.get(0);
        System.out.println(map[0][0]);
    }
}

The output will print correctly 1 , showing that there is no null pointer exception.


问:
How to execute Cypher in a file?
I am working on windows. I have created a text file of Cypher query using notepad. How can I run the query in the file using Neo4jShell or Neo4j web interface console.</p>

答:
./bin/neo4j-shell -path ../data/databases/ -c < commands.cql

on Neo4j    3.2.1

Title: How to execute Cypher in a file?