title: Spring Boot JPA custom query suddenly stopped working
body: <p>So this is frustrating, i went about testing a session system i was implementing, I only worked with session variables, did NOT change anything in my database, my models or my repositories and all of a sudden JPA just stopped recognizing my table. I got the following error :</p>
  <blockquote>
  <p>Unknown column 't' in 'field list'</p>
  </blockquote>
  <p>and when i change the custom query to use the table i get</p>
  <blockquote>
  <p>Unknown table '**_dev.ticket'</p>
  </blockquote>
  <p>This is really wierd. everything worked fine, it just stopped working. i did not even restart the debugging session.</p>
  <p>For more reference here is my repository code for this function:</p>
  <pre><code>@Query(nativeQuery = true, value = &quot;select t.*, s.name as status, agent.name_surname as assigned, CAST(t.dt_created as VARCHAR(20)) as created from ticket t left join ticket_agent ta on t.id = ta.ticket_id and ta.active = true left join web_users agent on agent.id = ta.agent_id inner join ticket_status ts on t.id = ts.ticket_id and ts.isset inner join status s on ts.status_id = s.id where t.logged_by_id = :clientId and (s.name like :searchStr or t.subject like :searchStr or CAST(t.dt_created as VARCHAR(16)) like :searchStr or (case when agent.name_surname is null then 'Unassigned' else agent.name_surname end) like :searchStr) group by id&quot;)
  Page&lt;Ticket&gt; findClientTickets(@Param(&quot;clientId&quot;) long agent, @Param(&quot;searchStr&quot;) String name, Pageable pageable);
  </code></pre>
  <p>Here is my model :</p>
  <pre><code>@Entity(name = &quot;ticket&quot;)
  @Table(name = &quot;ticket&quot;)
  public class Ticket {
     @Id
     @GeneratedValue
     @Column(nullable = false)
     private long id;
     @Column(nullable = false)
     private String subject;
     @Column(nullable = false, length = 512)
     private String description;
     @Column()
     private String affected;
     @OneToOne
     @JoinColumn(name = &quot;logged_by_id&quot;, nullable = false)
     private WebUser loggedBy;
     @Column(length = 1024)
     private String resolution;
     @Column(name = &quot;dt_created&quot;, nullable = false)
     private Date created;
     @Column(name = &quot;dt_resolved&quot;)
     private Date Resolved;
     @Column(name = &quot;dt_closed&quot;)
     private Date Closed;
     @OneToOne
     @JoinColumn()
     private Thread thread;
     @OneToMany
     @JoinColumn(name = &quot;ticket_id&quot;)
     private List&lt;TicketAgent&gt; ticketAgent = new ArrayList&lt;&gt;();
     @OneToMany
     @JoinColumn(name = &quot;ticket_id&quot;)
     private List&lt;TicketStatus&gt; ticketStatus = new ArrayList&lt;&gt;();
     @ManyToOne
     @JoinColumn(nullable = false)
     private ServiceType service;
     @OneToMany
     @JoinColumn(name = &quot;ticket_id&quot;)
     private List&lt;TicketAttachment&gt; ticketAttachment = new ArrayList&lt;&gt;();
     @ManyToOne
     @JoinColumn()
     private ClientAddress address;
     @ManyToOne
     @JoinColumn()
     private SLA sla;
     @Column(name = &quot;is_billable&quot;, nullable = false)
     private boolean isBillable;
     @Column(name = &quot;is_onsite&quot;, nullable = false)
     private boolean isOnsite;
     @Column(nullable = false)
     private int priority;
     @OneToMany
     @JoinColumn(name = &quot;ticket_id&quot;)
     private List&lt;TicketNote&gt; notes = new ArrayList&lt;&gt;();
     public Ticket(){
     }
     public long getId(){
         return this.id;
     }
     public String getSubject(){
         return this.subject;
     }
     public String getDescription(){
         return this.description;
     }
     public String getAffected(){
         return this.affected;
     }
     public WebUser getLoggedBy(){
         return this.loggedBy;
     }
     public String getResolution(){
         return this.resolution;
     }
     public Date getResolved(){
         return this.Resolved;
     }
     public Date getClosed(){
         return this.Closed;
     }
     public Thread getThread(){
         return this.thread;
     }
     public List&lt;TicketAgent&gt; getTicketAgent(){
         return this.ticketAgent;
     }
     public List&lt;TicketStatus&gt; getTicketStatus(){
         return this.ticketStatus;
     }
     public ServiceType getService(){
         return this.service;
     }
     public List&lt;TicketAttachment&gt; getTicketAttachment(){
         return this.ticketAttachment;
     }
     public ClientAddress getAddress(){
         return this.address;
     }
     public SLA getSla(){
         return this.sla;
     }
     public boolean isBillable(){
         return this.isBillable;
     }
     public boolean isOnsite(){
         return this.isOnsite;
     }
     public int getPriority(){
         return this.priority;
     }
     public List&lt;TicketNote&gt; getNotes(){
         return this.notes;
     }
     public void setSubject(String subject){
         this.subject = subject;
     }
  
     public void setDescription(String description){
         this.description = description;
     }
  
     public void setAffected(String affected){
         this.affected = affected;
     }
  
     public void setLoggedBy(WebUser loggedBy){
         this.loggedBy = loggedBy;
     }
  
     public void setResolution(String resolution){
         this.resolution = resolution;
     }
  
     public void setResolved(Date Resolved){
         this.Resolved = Resolved;
     }
  
     public void setClosed(Date Closed){
         this.Closed = Closed;
     }
  
     public void setThread(Thread thread){
         this.thread = thread;
     }
  
     public void setService(ServiceType service){
         this.service = service;
     }
  
     public void setAddress(ClientAddress address){
         this.address = address;
     }
  
     public void setSla(SLA sla){
         this.sla = sla;
     }
  
     public void setIsBillable(boolean isBillable){
         this.isBillable = isBillable;
     }
  
     public void setIsOnsite(boolean isOnsite){
         this.isOnsite = isOnsite;
     }
  
     public void setPriority(int priority){
         this.priority = priority;
     }
  
     public void setNotes(List&lt;TicketNote&gt; notes){
         this.notes = notes;
     }
  
  //CODE_START
  
     public void addAttachment(String filepath) {
         TicketAttachment ticketAttachment = new TicketAttachment(this, filepath);
         if (this.ticketAttachment == null) {
             this.ticketAttachment = new ArrayList&lt;&gt;();
         }
         this.ticketAttachment.add(ticketAttachment);
     }
  
     public TicketStatus getStatus() {
         long maxDate = 0;
         TicketStatus mostRecentTicketStatus = null;
  
         for (TicketStatus ticketStatus : this.ticketStatus) {
             long time = ticketStatus.getCreated().getTime();
             if (time &gt; maxDate &amp;&amp; ticketStatus.isSet()) {
                 maxDate = time;
                 mostRecentTicketStatus = ticketStatus;
             }
         }
         return mostRecentTicketStatus;
     }
  
     public String getTicketClass() {
         TicketStatus latestTicket = getStatus();
  
         if (latestTicket == null) {
             return &quot;badge badge-warning&quot;;
         }
  
         Status status = latestTicket.getStatus();
         int id = status.getColor();
  
         switch (id) {
             case 0:
                 return &quot;badge badge-info&quot;;
             case 1:
                 return &quot;badge badge-danger&quot;;
             case 2:
                 return &quot;badge badge-primary&quot;;
             case 3:
                 return &quot;badge badge-success&quot;;
             default:
                 return &quot;badge badge-success&quot;;
         }
     }
  
     public String getCreated() {
         SimpleDateFormat simpleDateFormat = new SimpleDateFormat(&quot;yyyy-MM-dd : HH:mm&quot;);
         return simpleDateFormat.format(created);
     }
  
     public WebUser getAgent() {
         for (TicketAgent agent : ticketAgent) {
             if (agent.isActive())
                 return agent.getAgent();
         }
         return null;
     }
  
     public boolean hasAgent(){
         return getAgent() != null;
     }
  
     public void create() {
         if (this.created == null)
             this.created = new Date();
     }
  
  } 
  </code></pre>
  <p>Can anyone please explain to me how this can happen and maybe why?
  The table does exist in the database, if i copy and paste the raw sql I also get a valid result from the database(OUTSIDE SPRING BOOT and JPA)</p>
  <p>I might be stupid now, but im unable to find anything that closely resembles my problem.
  I would've understood if i changed something in the database, model or repository but i did not.</p>
  <p>It literally just started to appear.</p>
  <p>Am i doing something wrong? Please help.</p>
  <p><strong><strong><strong><strong>UPDATE</strong></strong></strong></strong>***</p>
  <p>If i log in as another user everything just magically works again even though i use the exact same parameters....
  This has to be a caching issue. can anyone tell me how i can clear ALL the cache, tomcat included.</p>