title: Error accessing field [xxx] by reflection for persistent property with IllegalArgumentException
body: <p>I have 4 classes associated with each other as you see below in Spring Boot project. </p>
  
  <p>When i save a <strong>thread</strong> object through ThreadRepository, there is no problem. Automaticly  <code>List&lt;Tweet&gt; listOfTweets</code> All <code>Tweet</code> objects in the list are saved in the database. When I want to <strong>get all tweets in Tweet table</strong>, I see an error like that in the browser. (part of the output) I mean, There is no problem when you want to save them to database but if you want get them, there is a problem.</p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Can not set java.lang.String field com.savetweet.tweet.domain.Tweet.tweet_id to java.lang.Long</p>
    
    <p>Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1</p>
  </blockquote>
  
  <p><code>tweet_id</code> already have String type. But I don't know why it want to change to Long type. </p>
  
  <p>Database process doing through Tweet/Thread/Media/LinkRepository interface: (i.e)</p>
  
  <pre><code>@Repository
  public interface TweetRepository extends JpaRepository&lt;Tweet,Long&gt; {
  
  
  }
  </code></pre>
  
  <p>TweetServiceImp:</p>
  
  <pre><code>@Service
  public class TweetServiceImp implements TweetService  {
      private final static Logger log = LoggerFactory.getLogger(TweetServiceImp.class);
  
      private final TweetRepository tweetRepository;
  
  
      public TweetServiceImp(TweetRepository tweetRepository) {
          this.tweetRepository = tweetRepository;
      }
  
  
  
      @Override
      public List&lt;Tweet&gt; findAllTweets() {
          return tweetRepository.findAll();
      }
  
  
  
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@Controller
  public class SerieController {
      private final TweetService tweetService;
      private final ThreadService threadService;
  
  
      public SerieController(TweetService tweetService, ThreadService threadService) {
          this.tweetService = tweetService;
          this.threadService = threadService;
  
      }
  
  
      @RequestMapping(value = "/series/allTweets")
      @ResponseBody
      public List&lt;Tweet&gt; getAllTweets(){
          return tweetService.findAllTweets();
  
      }
  }
  </code></pre>
  
  <p>Thread Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_thread")
  @Getter @Setter @ToString
  public class Thread implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private Long id;
      @Column(unique = true,name = "thread_id")
      private String threadId;
      @Transient
      private Tweet mainTweet;
      @OneToMany(mappedBy = "thread",cascade = CascadeType.ALL)
      private List&lt;Tweet&gt; listOfTweets = new ArrayList&lt;Tweet&gt;();
  </code></pre>
  
  <p>Tweet Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_tweet")
  @Getter @Setter @ToString
  public class Tweet implements Serializable {
      private static final long serialVersionUID = 1L;
  
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private long id;
      @Column(unique = true, nullable = false,name = "tweet_id")
      private String tweet_id;
      @Column(name = "parent_tweet_id")
      private String parentTweetID;
      @Column(name = "avatar")
      private String avatar;
      @Column(name = "owner_id")
      private long owner_id;
      @Column(name = "owner_name")
      private String owner_name;
      @Column(name = "owner_nick")
      private String owner_nick;
      @Column(name = "content")
      private String content;
      @Column(name = "sent_time")
      private String sent_time;
      @Column(name = "sent_date")
      private String sent_date;
      @Column(name = "retweet_count")
      private String retweet_count;
      @Column(name = "like_count")
      private String like_count;
      @Transient
      private String quotedTweetHtml;
  
      @ManyToOne
      @JoinColumn(name = "thread_id",referencedColumnName = "thread_id")
      private Thread thread = new Thread();
  
      @OneToMany(mappedBy = "tweet",cascade = CascadeType.ALL)
      private List&lt;Media&gt; mediaURLs = new ArrayList&lt;Media&gt;();
  
      @OneToOne(mappedBy = "tweet",cascade = CascadeType.ALL  )
      private Link link;
  </code></pre>
  
  <p>Link Entity:</p>
  
  <pre><code>@Entity
  @Getter @Setter @ToString
  public class Link implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      @Column(name = "id")
      private long id;
      @Column(name = "attachment_type")
      private String attachmentType;
      @Column(name = "title")
      private String title;
      @Column(name = "description")
      private String description;
      @Column(name = "image")
      private String image;
      @Column(name = "url")
      private String url;
      @Column(name = "type")
      private String type;
      @Column(name = "video_url")
      private String videoUrl;
      @Column(name = "video_secure_url")
      private String videoSecureUrl;
      @OneToOne(fetch = FetchType.LAZY)
      @JoinColumn(name = "tweet_id",referencedColumnName = "tweet_id")
      private Tweet tweet;
  </code></pre>
  
  <p>Media Entity:</p>
  
  <pre><code>@Entity
  @Table(name = "tbl_media")
  @Getter @Setter @ToString
  public class Media implements Serializable {
      private static final long serialVersionUID = 1L;
  
      @Id
      @GeneratedValue(strategy = GenerationType.IDENTITY)
      private long id;
      @Column(name = "media_id")
      private String mediaID;
      @Column(name = "media_type")
      private String mediaType;
      @Column(name = "media_url")
      private String mediaUrl;
      @Column(name = "media_url_https")
      private String mediaUrlHttps;
      @Column(name = "media_video_url")
      private String mediaVideoUrl;
      @ManyToOne
      @JoinColumn(name = "tweet_id",referencedColumnName = "tweet_id")
      private Tweet tweet;
  </code></pre>
  
  <p>Full output:</p>
  
  <blockquote>
    <p>There was an unexpected error (type=Internal Server Error, status=500).
    Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1
    org.springframework.orm.jpa.JpaSystemException: Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1; nested exception is org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:351)
        at org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:253)
        at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.translateExceptionIfPossible(AbstractEntityManagerFactoryBean.java:527)
        at org.springframework.dao.support.ChainedPersistenceExceptionTranslator.translateExceptionIfPossible(ChainedPersistenceExceptionTranslator.java:61)
        at org.springframework.dao.support.DataAccessUtils.translateIfNecessary(DataAccessUtils.java:242)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:153)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.jpa.repository.support.CrudMethodMetadataPostProcessor$CrudMethodMetadataPopulatingMethodInterceptor.invoke(CrudMethodMetadataPostProcessor.java:135)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.repository.core.support.SurroundingTransactionDetectorMethodInterceptor.invoke(SurroundingTransactionDetectorMethodInterceptor.java:61)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
        at com.sun.proxy.$Proxy96.findAll(Unknown Source)
        at com.savetweet.tweet.Service.Imp.TweetServiceImp.findAllTweets(TweetServiceImp.java:68)
        at com.savetweet.tweet.rest.SerieController.getAllTweets(SerieController.java:40)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:189)
        at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138)
        at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:102)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895)
        at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:800)
        at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
        at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1038)
        at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942)
        at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005)
        at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:897)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)
        at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:882)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:99)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:92)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:93)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:200)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
        at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408)
        at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
        at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:834)
        at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1417)
        at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.base/java.lang.Thread.run(Thread.java:844)
    Caused by: org.hibernate.property.access.spi.PropertyAccessException: Error accessing field [private java.lang.String com.savetweet.tweet.domain.Tweet.tweet_id] by reflection for persistent property [com.savetweet.tweet.domain.Tweet#tweet_id] : 1
        at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:75)
        at org.hibernate.tuple.component.AbstractComponentTuplizer.getPropertyValue(AbstractComponentTuplizer.java:59)
        at org.hibernate.type.ComponentType.getPropertyValue(ComponentType.java:412)
        at org.hibernate.type.ComponentType.getHashCode(ComponentType.java:239)
        at org.hibernate.engine.spi.EntityUniqueKey.generateHashCode(EntityUniqueKey.java:67)
        at org.hibernate.engine.spi.EntityUniqueKey.(EntityUniqueKey.java:48)
        at org.hibernate.type.EntityType.loadByUniqueKey(EntityType.java:733)
        at org.hibernate.type.EntityType.resolve(EntityType.java:467)
        at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:172)
        at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:129)
        at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1151)
        at org.hibernate.loader.Loader.processResultSet(Loader.java:1010)
        at org.hibernate.loader.Loader.doQuery(Loader.java:948)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:340)
        at org.hibernate.loader.Loader.doList(Loader.java:2689)
        at org.hibernate.loader.Loader.doList(Loader.java:2672)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2506)
        at org.hibernate.loader.Loader.list(Loader.java:2501)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:504)
        at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:395)
        at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:220)
        at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1508)
        at org.hibernate.query.internal.AbstractProducedQuery.doList(AbstractProducedQuery.java:1537)
        at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1505)
        at org.hibernate.query.Query.getResultList(Query.java:135)
        at org.hibernate.query.criteria.internal.compile.CriteriaQueryTypeQueryAdapter.getResultList(CriteriaQueryTypeQueryAdapter.java:74)
        at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:306)
        at org.springframework.data.jpa.repository.support.SimpleJpaRepository.findAll(SimpleJpaRepository.java:73)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:564)
        at org.springframework.data.repository.core.support.RepositoryComposition$RepositoryFragments.invoke(RepositoryComposition.java:359)
        at org.springframework.data.repository.core.support.RepositoryComposition.invoke(RepositoryComposition.java:200)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$ImplementationMethodExecutionInterceptor.invoke(RepositoryFactorySupport.java:644)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.doInvoke(RepositoryFactorySupport.java:608)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$invoke$3(RepositoryFactorySupport.java:595)
        at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.invoke(RepositoryFactorySupport.java:595)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.data.projection.DefaultMethodInvokingMethodInterceptor.invoke(DefaultMethodInvokingMethodInterceptor.java:59)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:294)
        at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:98)
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
        at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:139)
        ... 65 more
    Caused by: java.lang.IllegalArgumentException: Can not set java.lang.String field com.savetweet.tweet.domain.Tweet.tweet_id to java.lang.Long
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:167)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.throwSetIllegalArgumentException(UnsafeFieldAccessorImpl.java:171)
        at java.base/jdk.internal.reflect.UnsafeFieldAccessorImpl.ensureObj(UnsafeFieldAccessorImpl.java:58)
        at java.base/jdk.internal.reflect.UnsafeObjectFieldAccessorImpl.get(UnsafeObjectFieldAccessorImpl.java:36)
        at java.base/java.lang.reflect.Field.get(Field.java:418)
        at org.hibernate.property.access.spi.GetterFieldImpl.get(GetterFieldImpl.java:71)
        ... 110 more</p>
  </blockquote>
  
  <p>Hibernate Output (with findAllTweets()): </p>
  
  <pre><code>Hibernate:
          select
          tweet0_.id as id1_3_,
          tweet0_.avatar as avatar2_3_,
          tweet0_.content as content3_3_,
          tweet0_.like_count as like_cou4_3_,
          tweet0_.owner_id as owner_id5_3_,
          tweet0_.owner_name as owner_na6_3_,
          tweet0_.owner_nick as owner_ni7_3_,
          tweet0_.parent_tweet_id as parent_t8_3_,
          tweet0_.retweet_count as retweet_9_3_,
          tweet0_.sent_date as sent_da10_3_,
          tweet0_.sent_time as sent_ti11_3_,
          tweet0_.thread_id as thread_13_3_,
          tweet0_.tweet_id as tweet_i12_3_
          from
          tbl_tweet tweet0_
          Hibernate:
          select
          thread0_.id as id1_2_0_,
          thread0_.thread_id as thread_i2_2_0_
          from
          tbl_thread thread0_
          where
          thread0_.thread_id=?
  </code></pre>