title: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 for OneToOne annotation
body: <p>I made a login jsp,
  I am using Hibernate OneToOne annotation that for useradmin and wafat, 
  class useradmin for login if there is for PK(useradmin) record in wafat is fine but when there is no PK(useradmin) record in wafat I got this error ~ 
  <code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0</code></p>
  
  <p>this my ERD ~</p>
  
  <p><a href="https://i.stack.imgur.com/2Pj22.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2Pj22.jpg" alt="enter image description here"></a></p>
  
  <p>this is record from wafat table,</p>
  
  <p><a href="https://i.stack.imgur.com/4ybBi.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4ybBi.jpg" alt="enter image description here"></a></p>
  
  <p>this is record from user table,</p>
  
  <p><a href="https://i.stack.imgur.com/GXVPB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GXVPB.jpg" alt="enter image description here"></a></p>
  
  <p>this is useradmin class,</p>
  
  <pre><code>package org.ppbni.splatter.model;
  
  import java.io.Serializable;
  import java.util.Date;
  import javax.persistence.Column;
  import javax.persistence.GeneratedValue;
  import javax.persistence.Id;
  import javax.persistence.Entity;
  import javax.persistence.PrimaryKeyJoinColumn;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  import javax.persistence.OneToOne;
  import javax.persistence.CascadeType;
  
  @SuppressWarnings("serial")
  @Entity
  @Table(name="user")
  public class UserAdmin implements Serializable{
  
  @Id
  @GeneratedValue
  @Column(name="no_dana", unique=true, nullable=false)
  private String no_dana;
  
  @Column(name="npp")
  private String npp;
  
  @Column(name="password")
  private String password;
  
  @OneToOne(mappedBy="useradmin", cascade=CascadeType.ALL)
  @PrimaryKeyJoinColumn
  private Wafat wafat;
  
  /**Setter and Getter Methods**/
  
  }
  </code></pre>
  
  <p>this is my wafat class,</p>
  
  <pre><code>package org.ppbni.splatter.model;
  
  import java.io.Serializable;
  import java.util.Date;
  import javax.persistence.Column;
  import javax.persistence.Id;
  import javax.persistence.Entity;
  import javax.persistence.JoinColumn;
  import javax.persistence.MapsId;
  import javax.persistence.OneToOne;
  import javax.persistence.Table;
  import javax.persistence.Temporal;
  import javax.persistence.TemporalType;
  
  @SuppressWarnings("serial")
  @Entity
  @Table(name="wafat")
  public class Wafat implements Serializable{
  
  @Id
  @Column(name="kode_wafat", unique=true, nullable=false)
  private String kode_wafat;
  
  @Id
  @JoinColumn(name="no_dana")
  private String no_dana;
  
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name="tgl_wafat")
  
  @Column(name="usia_wafat")
  private Date tgl_wafat;
  
  @Column(name="usia_wafat")
  private int usia_wafat;
  
  @Temporal(TemporalType.TIMESTAMP)
  @Column(name="tgl_makam")
  private Date tgl_makam;
  
  @Column(name="tempat_makam")
  private String tempat_makam;
  
  @OneToOne
  @MapsId
  @JoinColumn(name="no_dana")
  private UserAdmin useradmin;
  
  /**Setter and Getter Methods**/
  }
  </code></pre>
  
  <p>this is ny login controller,</p>
  
  <pre><code>@RequestMapping(value="/afterlogin.html", method = RequestMethod.GET)
  public String directIndex(ModelMap model) {
      User user = (User)SecurityContextHolder.getContext().getAuthentication().getPrincipal();
      String sessionUser = user.getUsername();
  
      try {
          UserAdmin dataUser = userService.get(sessionUser);
          String userAuth = dataUser.getAuthority();
          System.out.println(userAuth);
          if(userAuth.equals("ROLE_ANGGOTA") || userAuth.equals("ROLE_PENGURUS")){
              return "redirect:/user/index.html";
          }
          else if(userAuth.equals("ROLE_ADMIN")){
              return "redirect:/admin/index.html";
          }
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  
  <p>this the error ~ </p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
  at java.util.ArrayList.rangeCheck(Unknown Source)
  at java.util.ArrayList.get(Unknown Source)
  at org.ppbni.splatter.dao.impl.UserDaoImpl.get(UserDaoImpl.java:33)
  at org.ppbni.splatter.service.impl.UserServiceImpl.get(UserServiceImpl.java:21)
  at org.ppbni.splatter.web.controller.LoginController.directIndex(LoginController.java:39)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
  at java.lang.reflect.Method.invoke(Unknown Source)
  at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:219)
  at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)
  at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
  at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
  at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
  at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
  at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:856)
  at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:936)
  at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:827)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
  at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:812)
  at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
  at com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
  at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
  at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
  at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
  at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
  at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
  at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
  at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:936)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
  at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1004)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
  at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
  at java.lang.Thread.run(Unknown Source)
  </code></pre>
  
  <p>this is the part of my dao,</p>
  
  <pre><code>@SuppressWarnings("unchecked")
  @Override
  public UserAdmin get(String no_dana)throws Exception{
  
      DetachedCriteria criteria = DetachedCriteria.forClass(UserAdmin.class).add(Restrictions.eq("no_dana", no_dana));
      List&lt;UserAdmin&gt; userList = getHibernateTemplate().findByCriteria(criteria);
      return userList.get(0);
  
  }
  </code></pre>
  
  <p>any help will be pleasure :)</p>