title: java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
body: <p>I know this has been asked many times, but none of the answers have solved the problem so far.</p>
  <p>My code was working perfectly for years up until I upgraded from <strong>Hibernate 4.3.11</strong> to <strong>Hibernate 5.2.0</strong>. Now I'm getting the following error:</p>
  <pre><code>java.lang.IllegalArgumentException: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select password, salt from User where userName=:fullName and distributor_id is null]
  at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:131)
  at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:155)
  at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:162)
  at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:633)
  at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:101)
  at com.stuhrling.service.authentication.AuthenticationService.authenticate(AuthenticationService.java:103)
  at com.stuhrling.service.authentication.AuthenticationService.processLogin(AuthenticationService.java:42)
  at com.stuhrling.interceptor.AuthenticationInterceptor.intercept(AuthenticationInterceptor.java:60)
  at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
  at com.stuhrling.interceptor.OpenSessionInViewInterceptor.intercept(OpenSessionInViewInterceptor.java:189)
  at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
  at com.stuhrling.interceptor.SessionMessageInterceptor.intercept(SessionMessageInterceptor.java:55)
  at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:245)
  at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:54)
  at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:575)
  at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
  at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:99)
  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
  at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
  at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
  at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
  at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
  at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
  at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
  at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
  at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
  at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
  at org.apache.coyote.ajp.AjpAprProcessor.process(AjpAprProcessor.java:188)
  at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
  at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2476)
  at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2465)
  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
  at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
  at java.lang.Thread.run(Thread.java:748)
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped [select password, salt from User where userName=:fullName and distributor_id is null]
      at org.hibernate.hql.internal.ast.QuerySyntaxException.generateQueryException(QuerySyntaxException.java:79)
      at org.hibernate.QueryException.wrapWithQueryString(QueryException.java:103)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:218)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:142)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:115)
      at org.hibernate.engine.query.spi.HQLQueryPlan.&lt;init&gt;(HQLQueryPlan.java:77)
      at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:152)
      at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:523)
      at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:625)
      ... 31 more
  Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: User is not mapped
      at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:171)
      at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:91)
      at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:79)
      at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:321)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3704)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3593)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:718)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:574)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:311)
      at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:259)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:262)
      at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:190)
      ... 37 more
  </code></pre>
  <p>Most answers were that the Entity should be queried, not the table, which I indeed did.</p>
  <p>Code for the <strong>User</strong> class:</p>
  <pre><code>package com.stuhrling.domain.user;
  
  import com.stuhrling.domain.customerservice.ProcessingLocation;
  import com.stuhrling.domain.distributor.Distributor;
  import com.stuhrling.domain.favorites.FavoritesItem;
  import com.stuhrling.domain.offer.Customer;
  import com.stuhrling.domain.offer.Offer;
  import com.stuhrling.domain.permissions.Group;
  import com.stuhrling.domain.permissions.Permission;
  import com.stuhrling.domain.permissions.PermissionList;
  import com.stuhrling.domain.permissions.PermissionsSchema;
  import com.stuhrling.domain.shoppingcart.ShoppingCartItem;
  import com.stuhrling.persistence.HibernateUtil;
  import com.stuhrling.persistence.PersistenceException;
  import com.stuhrling.util.EqualsUtil;
  
  import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.TreeSet;
  
  import javax.persistence.CascadeType;
  import javax.persistence.Column;
  import javax.persistence.Entity;
  import javax.persistence.GeneratedValue;
  import javax.persistence.GenerationType;
  import javax.persistence.Id;
  import javax.persistence.JoinColumn;
  import javax.persistence.JoinTable;
  import javax.persistence.ManyToMany;
  import javax.persistence.ManyToOne;
  import javax.persistence.MapKey;
  import javax.persistence.MapKeyColumn;
  import javax.persistence.OneToMany;
  import javax.persistence.OrderBy;
  import javax.persistence.Table;
  import javax.persistence.Transient;
  import javax.persistence.UniqueConstraint;
  
  import org.apache.log4j.Logger;
  import org.hibernate.annotations.Cascade;
  import org.hibernate.annotations.IndexColumn;
  import org.jdom2.JDOMException;
  
  @Entity
  @Table(name = &quot;USER&quot;, uniqueConstraints = {
      @UniqueConstraint(columnNames = {&quot;user_name&quot;})})
  public class User {
  
      private static final int MAX_MRU_SIZE = 10;
      private static final Logger log = Logger.getLogger(User.class);
  
      public final static String ADMIN = &quot;ADMIN&quot;;
      public final static String GENERAL = &quot;GENERAL&quot;;
      public final static String DISTRIBUTOR = &quot;DISTRIBUTOR&quot;;
      public final static String MANUFACTURING = &quot;MANUFACTURING&quot;;
      public final static String PRODUCT_DEVELOPMENT = PRODUCT_DEVELOPMENT&quot;;
      public final static String PHOTOGRAPHY = &quot;PHOTOGRAPHY&quot;;
      public static final String ACCOUNT_MANAGER = &quot;ACCOUNT_MANAGER&quot;;
      public static final String ADMINISTRATOR = &quot;ADMINISTRATOR&quot;;
      public static final String CUSTOMER_SERVICE = &quot;CUSTOMER_SERVICE&quot;;
      public static final String GENERAL_ACCESS = &quot;GENERAL_ACCESS&quot;;
      public static final String PRODUCT_AUTHOR = &quot;PRODUCT_AUTHOR&quot;;
      public static final String SHIPPING_RECEIVING = &quot;SHIPPING_RECEIVING&quot;;
      public static final String SUPPLIER = &quot;SUPPLIER&quot;;
  
      @Column(name = &quot;calendar_email_subscribe&quot;)
      private Boolean calendarEmailSubscribe;
      
      @Column(name = &quot;must_reset_password&quot;)
      private Boolean mustResetPassword;
  
      @Transient
      private String xmlFile = &quot;permissions.xml&quot;;
  
      @SuppressWarnings(&quot;unused&quot;)
      @Column(name = &quot;salt&quot;)
      private String salt;
  
      @Column(name = &quot;permission_snapshot&quot;)
      private boolean permissionCompanySnapshot = false;
  
      @Column(name = &quot;permission_distributor_file_upload&quot;)
      private boolean permissionDistributorFileUpload = false;
      
      public boolean isPermissionDistributorFileUpload() {
          return permissionDistributorFileUpload;
      }
  
      public void setPermissionDistributorFileUlpoad(boolean permissionDistributorFileUlpoad) {
          this.permissionDistributorFileUpload = permissionDistributorFileUlpoad;
      }
  
      @Column(name = &quot;full_name&quot;)
      private String fullName;
  
      @Column(name = &quot;session_brand_mode&quot;)
      private String sessionBrandMode;
  
      @Column(name = &quot;is_admin&quot;)
      private boolean admin = false;
  
      @Column(name = &quot;exec_admin&quot;)
      private boolean execAdmin = false;
      
      @Column(name = &quot;snap_shot_preferance&quot;, nullable = false, columnDefinition = &quot;varchar(255) default 'false|5|0|1|0|0|5|0|1'&quot;)
      private String snapShotPreferance = &quot;false|5|0|1|0|0|5|0|1&quot;; /
  
      @OneToMany
      @MapKeyColumn(name = &quot;brand&quot;)
      @Cascade({org.hibernate.annotations.CascadeType.SAVE_UPDATE})
      Map&lt;String, PermissionList&gt; brandPermissions = new HashMap&lt;String, PermissionList&gt;();
      
      @Column(name = &quot;password&quot;)
      private String password;
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      private int id;
  
      @Column(name = &quot;user_name&quot;)
      private String userName;
  
      @Column
      private boolean archived = false;
      
      @ManyToOne
      @JoinColumn(name = &quot;distributor_id&quot;, nullable = true)
      private Distributor distributor;
  
      @Column(name = &quot;user_type&quot;)
      private String userType;
      
      @Column(name = &quot;email&quot;)
      private String email;
  
      @OneToMany(mappedBy = &quot;user&quot;, cascade = CascadeType.ALL)
      @OrderBy(&quot;brand asc&quot;)
      List&lt;ShoppingCartItem&gt; cart = new ArrayList&lt;ShoppingCartItem&gt;();
  
      @OneToMany(mappedBy = &quot;user&quot;, cascade = CascadeType.ALL)
      List&lt;FavoritesItem&gt; favorites = new ArrayList&lt;FavoritesItem&gt;();
      
      @OneToMany
      @MapKey(name = &quot;id&quot;)
      @JoinTable(name = &quot;USER_OFFERS&quot;, joinColumns = {
          @JoinColumn(name = &quot;user_id&quot;)}, inverseJoinColumns = {
          @JoinColumn(name = &quot;offer_id&quot;)})
      Map&lt;Integer, Offer&gt; userLists = new HashMap&lt;Integer, Offer&gt;();
  
      @OneToMany
      @IndexColumn(name = &quot;idx&quot;)
      @JoinTable(name = &quot;USER_MRU_OFFERS&quot;, joinColumns = {
          @JoinColumn(name = &quot;user_id&quot;)}, inverseJoinColumns = {
          @JoinColumn(name = &quot;offer_id&quot;)})
      List&lt;Offer&gt; mostRecentlyUsedLists = new LinkedList&lt;Offer&gt;();
  
      @ManyToMany(mappedBy = &quot;accountManagers&quot;)
      private Set&lt;Customer&gt; accounts = new TreeSet&lt;Customer&gt;();
  
      @Column(name = &quot;vendor&quot;)
      private String vendor;
  
      @Column(name = &quot;brand&quot;)
      private String brand;
      
      @Column(name = &quot;permission_edit&quot;)
      private boolean permissionToEdit;
  
      @Column(name = &quot;role&quot;)
      private String role;
  
      @Column(name = &quot;last_login&quot;)
      private Date lastLogin;
      
      public String getXmlFile() {
          return xmlFile;
      }
  
      public void setXmlFile(String xmlFile) {
          this.xmlFile = xmlFile;
      }
  
      public boolean isPermissionCompanySnapshot() {
          return permissionCompanySnapshot;
      }
  
      public void setPermissionCompanySnapshot(boolean permissionCompanySnapshot) {
          this.permissionCompanySnapshot = permissionCompanySnapshot;
      }
  
      public String getSnapShotPreferance() {
          return snapShotPreferance;
      }
  
      public void setSnapShotPreferance(String snapShotPreferance) {
          this.snapShotPreferance = snapShotPreferance;
      }
  
      public boolean isExecAdmin() {
          return execAdmin;
      }
  
      public void setExecAdmin(boolean execAdmin) {
          this.execAdmin = execAdmin;
      }
  
      public boolean isAdmin() {
          return admin;
      }
  
      public void setAdmin(boolean admin) {
          this.admin = admin;
      }
  
      public String getSessionBrandMode() {
          return sessionBrandMode;
      }
  
      public void setSessionBrandMode(String sessionBrandMode) {
          this.sessionBrandMode = sessionBrandMode;
      }
  
      public boolean isArchived() {
          return archived;
      }
  
      public void archiveUser() {
          this.archived = true;
      }
  
      public void unarchiveUser() {
          this.archived = false;
      }
  
      public String getUserType() {
          return userType;
      }
  
      public void setUserType(String userType) {
          this.userType = userType;
      }
  
      public List&lt;FavoritesItem&gt; getFavorites() {
          return favorites;
      }
  
      public void setFavorites(List&lt;FavoritesItem&gt; favorites) {
          this.favorites = favorites;
      }
  
      public String getBrand() {
          return brand;
      }
  
      public void setBrand(String brand) {
          this.brand = brand;
          verifyAndResetBrandMode();
      }
  
      public List&lt;Offer&gt; getUserLists() {
          List&lt;Offer&gt; list = new ArrayList&lt;Offer&gt;();
          list.addAll(userLists.values());
          return list;
      }
  
      public String getEmail() {
          return email;
      }
  
      public void setEmail(String email) {
          this.email = email;
      }
  
      public int getId() {
          return id;
      }
      
      public String getFullName() {
          return fullName;
      }
  
      public String getPassword() {
          return password;
      }
  
      public int getUserId() {
          return id;
      }
  
      public String getUserName() {
          return userName;
      }
    
      public void setFullName(String fullName) {
          this.fullName = fullName;
      }
  
      public void setPassword(String password) {
          this.password = password;
      }
  
      public void setUserId(int userId) {
          this.id = userId;
      }
  
      public void setUserName(String userName) {
          this.userName = userName;
      }
  
      public void setSalt(String salt) {
          this.salt = salt;
      }
  
      public Offer getUserList(int id) {
          Offer list = userLists.get(id);
          addToMostRecentlyUsedLists(list);
          return list;
      }
  
      public Map&lt;Integer, Offer&gt; getAllUserLists() {
          return userLists;
      }
      
      public void removeList(Offer offer) {
          userLists.remove(offer.getId());
      }
  
      public void addToMostRecentlyUsedLists(Offer list) {
          if (list == null) {
              return;
          }
  
          mostRecentlyUsedLists.remove(list);
          mostRecentlyUsedLists.add(0, list);
  
          while (mostRecentlyUsedLists.size() &gt; MAX_MRU_SIZE) {
              mostRecentlyUsedLists.remove(mostRecentlyUsedLists.size() - 1);
          }
      }
  
      public List&lt;Offer&gt; getRecentlyUsedLists() {
          return mostRecentlyUsedLists;
      }
  
      public boolean getPermissionToEdit() {
          return permissionToEdit;
      }
  
      public void setPermissionToEdit(boolean permissionToEdit) {
          this.permissionToEdit = permissionToEdit;
      }
  
      public String getRole() {
          return role;
      }
  
      public boolean isRole(String r) {
          return role != null &amp;&amp; role.contains(r);
      }
  
      public void setRole(String role) {
          this.role = role;
      }
  
      public void setLastLogin(Date date) {
          this.lastLogin = date;
      }
  
      public Date getLastLogin() {
          return lastLogin;
      }
  
      public String getVendor() {
          return vendor;
      }
  
      public void setVendor(String vendor) {
          this.vendor = vendor;
      }
  
      public boolean isRestrictedVendor() {
          return (this.vendor != null &amp;&amp; !this.vendor.equals(&quot;&quot;));
      }
  
      public Set&lt;Customer&gt; getAccounts() {
          return accounts;
      }
  
      public void setAccounts(Set&lt;Customer&gt; accounts) {
          this.accounts = accounts;
      }
  
      @Override
      public String toString() {
          return this.fullName;
      }
  
      public Boolean getCalendarEmailSubscribe() {
          return calendarEmailSubscribe;
      }
  
      public void setCalendarEmailSubscribe(Boolean calendarEmailSubscribe) {
          this.calendarEmailSubscribe = calendarEmailSubscribe;
      }
  
      public Distributor getDistributor() {
          return distributor;
      }
  
      public void setDistributor(Distributor distributor) {
          this.distributor = distributor;
      }
  
      public boolean isDistributor() {
          return this.distributor != null;
      }
  
      public boolean isPermissioned(String brand, String permission) {
          boolean hasPermission = false;
  
          if (brandPermissions.containsKey(brand)) {
              PermissionList permissionList = brandPermissions.get(brand);
              hasPermission = permissionList.hasPermission(permission);
          }
  
          return hasPermission;
      }
  
      @Transient
      private boolean isGroupPermissioned = false;
  
      public boolean isGroupPermissioned(String brand, String group) throws JDOMException, IOException {
          loopThroughGroups(brand, group);
  
          return isGroupPermissioned;
      }
  
      private void loopThroughGroups(String brand, String group) throws JDOMException, IOException {
          PermissionsSchema permissions = PermissionsSchema.getInstance(&quot;permissions.xml&quot;);
          List&lt;Group&gt; groups = permissions.getGroups();
  
          for (Group groupObj : groups) {
              if (groupObj.getName().equals(group)) {
                  isGroupPermissioned = true;
                  loopThroughPermissions(brand, group, groupObj);
              }
          }
      }
  
      private void loopThroughPermissions(String brand, String group, Group groupObj) {
          for (Permission permission : groupObj.getPermissions()) {
              if (!(isPermissioned(brand, permission.getName()))) {
                  isGroupPermissioned = false;
                  break;
              }
          }
      }
  
      public List&lt;ShoppingCartItem&gt; getCart() {
          return cart;
      }
  
      public void setCart(List&lt;ShoppingCartItem&gt; cart) {
          this.cart = cart;
      }
  
      public void addPermission(String brand, String permission) {
          if (brandPermissions.containsKey(brand)) {
              addPermissionToExistingValue(brand, permission);
          } else {
              addNewKeyAndValue(brand, permission);
          }
      }
  
      private void addPermissionToExistingValue(String brand, String permission) {
          PermissionList permissionList = brandPermissions.get(brand);
          permissionList.addPermission(permission);
      }
  
      private void addNewKeyAndValue(String brand, String permission) {
          PermissionList permissionList = new PermissionList();
          permissionList.addPermission(permission);
          brandPermissions.put(brand, permissionList);
      }
  
      public void removePermission(String brand, String permission) {
          if (brandPermissions.containsKey(brand)) {
              PermissionList permissionList = brandPermissions.get(brand);
              permissionList.removePermission(permission);
          }
      }
  
      public List&lt;String&gt; getPermissions(String brand) {
          List&lt;String&gt; permissionArrayList = null;
  
          if (brandPermissions.get(brand) != null) {
              PermissionList permissionList = brandPermissions.get(brand);
              permissionArrayList = permissionList.getPermissions();
          }
  
          return permissionArrayList;
      }
  
      public boolean isActionPermissioned(String brand, String action) throws IOException, JDOMException {
          boolean isActionPermissioned = false;
  
          PermissionsSchema schema = PermissionsSchema.getInstance(&quot;permissions.xml&quot;);
          List&lt;Permission&gt; permissions = schema.getPermissionsHavingAction(action);
  
          for (Permission permission : permissions) {
              if (isPermissioned(brand, permission.getName())) {
                  isActionPermissioned = true;
                  break;
              }
          }
  
          return isActionPermissioned;
      }
  
      public boolean hasPermissionInGroup(String brand, String group) throws JDOMException, IOException {
          boolean hasPermissionInGroup = false;
  
          PermissionsSchema permissions = PermissionsSchema.getInstance(xmlFile);
          List&lt;Group&gt; groups = permissions.getGroups();
  
          for (Group groupObj : groups) {
              if (groupObj.getName().equals(group)) {
                  List&lt;Permission&gt; permissionObjects = groupObj.getPermissions();
  
                  for (Permission element : permissionObjects) {
                      if (isPermissioned(brand, element.getName())) {
                          hasPermissionInGroup = true;
                          break;
                      }
                  }
  
                  break;
              }
          }
  
          return hasPermissionInGroup;
      }
  
      public boolean isPermissionedForBrand(String brandToCheck) {
          if (brand == null) {
              return false;
          }
  
          return brand.contains(brandToCheck);
      }
  
      public void verifyAndResetBrandMode() {
          if (sessionBrandMode == null || !isPermissionedForBrand(sessionBrandMode)) {
              if (brand != null &amp;&amp; !brand.isEmpty()) {
                  sessionBrandMode = brand.substring(0, 1);
              }
          }
      }
    
      public void setMustResetPassword(boolean mustResetPassword) {
          this.mustResetPassword = mustResetPassword;
      }
  
      public Map&lt;String, PermissionList&gt; getBrandPermissions() {
          return brandPermissions;
      }
  
      public void setBrandPermissions(Map&lt;String, PermissionList&gt; brandPermissions) {
          this.brandPermissions = brandPermissions;
      }
      
      @ManyToMany(cascade = CascadeType.ALL)
      @JoinTable(name = &quot;USER_PROCESSING_LOCATION&quot;, joinColumns = { @JoinColumn(name = &quot;user_id&quot;) }, inverseJoinColumns = { @JoinColumn(name = &quot;processing_location_id&quot;) })
      private final List&lt;ProcessingLocation&gt; processingLocations = new ArrayList&lt;ProcessingLocation&gt;();
      
      public List&lt;ProcessingLocation&gt; getProcessingLocations() {
          return processingLocations;
      }
      
      public void addProcessingLocation(ProcessingLocation processingLocation) {
          processingLocations.add(processingLocation);
      }
  
      public static void main(String[] args) throws PersistenceException {
          HibernateUtil.getCurrentSession();
      }
      
  }
  </code></pre>
  <p>Entity mapping for User, other entities ommited for brevity:</p>
  <pre><code>&lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;!-- Database connection settings --&gt;
          &lt;property name=&quot;connection.driver_class&quot;&gt;com.mysql.cj.jdbc.Driver&lt;/property&gt;
          &lt;property name=&quot;hibernate.connection.useUnicode&quot;&gt;true&lt;/property&gt;
          &lt;property name=&quot;hibernate.connection.characterEncoding&quot;&gt;UTF-8&lt;/property&gt;
  
  
          &lt;!-- Connection Pool Setting --&gt;
          &lt;property name=&quot;hibernate.c3p0.min_size&quot;&gt;0&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.max_size&quot;&gt;30&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.timeout&quot;&gt;300&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.max_statements&quot;&gt;50&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.idle_test_period&quot;&gt;90&lt;/property&gt;
  
          &lt;property name=&quot;hibernate.c3p0.unreturnedConnectionTimeout&quot;&gt;2700&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.debugUnreturnedConnectionStackTraces&quot;&gt;true&lt;/property&gt;
  
  
          &lt;property name=&quot;hibernate.c3p0.testConnectionOnCheckout&quot;&gt;true&lt;/property&gt;
          &lt;property name=&quot;hibernate.c3p0.preferredTestQuery&quot;&gt;SELECT 1&lt;/property&gt;
  
          &lt;!-- SQL dialect --&gt;
          &lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.MySQL5Dialect&lt;/property&gt;
  
          &lt;!-- Enable Hibernate's automatic session context management --&gt;
          &lt;property name=&quot;current_session_context_class&quot;&gt;thread&lt;/property&gt;
  
          &lt;!-- Disable the second-level cache --&gt;
          &lt;property name=&quot;cache.provider_class&quot;&gt;org.hibernate.cache.internal.NoCacheProvider&lt;/property&gt;
  
          &lt;!-- Echo all executed SQL to stdout --&gt;
          &lt;property name=&quot;show_sql&quot;&gt;false&lt;/property&gt;
  
          &lt;!-- Drop and re-create the database schema on startup --&gt;
  &lt;!--        &lt;property name=&quot;hbm2ddl.auto&quot;&gt;none&lt;/property&gt;--&gt;
          
          &lt;mapping class=&quot;com.stuhrling.domain.user.User&quot;/&gt;
     &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  <p>Here is the query code:</p>
  <pre><code>private List&lt;Object[]&gt; getUserRecords(login){
  
      Session session = HibernateUtil.getCurrentSession();
      Query hql = session.createQuery(&quot;select password, salt from User where userName=:fullName&quot;);
      hql.setString(&quot;fullName&quot;, login);
      List&lt;Object[]&gt; results = hql.list();
  
      if (results.size() &gt; 1) {
              throw new ServiceException(&quot;Database inconsistent two users with the same user name&quot;);
      }
  
      return results;
  }
  </code></pre>
  <p>Does anyone have any ideas? I'm pretty desperate, my work has pretty much ground to a halt...</p>
  <p>Any help would be greatly appreciated!</p>
  <p>UPDATE:
  Here I've posted the HibernateUtil class as requested:</p>
  <pre><code>package com.stuhrling.persistence;
  
  import org.apache.log4j.Logger;
  import org.hibernate.HibernateException;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.hibernate.boot.MetadataSources;
  import org.hibernate.boot.registry.StandardServiceRegistry;
  import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
  import org.hibernate.cfg.Configuration;
  
  
  import com.stuhrling.config.AppConfig;
  
  public class HibernateUtil {
      static Logger log = Logger.getLogger(HibernateUtil.class);
  
      private static SessionFactory sessionFactory;
      private static final ThreadLocal&lt;Session&gt; threadSession = new ThreadLocal&lt;&gt;();
  
      static {
          try {
              Class.forName(&quot;com.mysql.cj.jdbc.Driver&quot;);
  
              final Configuration configuration = new Configuration();
              configuration.configure();
  
              AppConfig appConfig = AppConfig.getInstance();
              configuration.setProperty(&quot;hibernate.connection.url&quot;, appConfig.getProperty(&quot;db.url&quot;));
              configuration.setProperty(&quot;hibernate.connection.username&quot;, appConfig.getProperty(&quot;db.username&quot;));
              configuration.setProperty(&quot;hibernate.connection.password&quot;, appConfig.getProperty(&quot;db.password&quot;));
  
              final StandardServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder()
                      .configure()
                      .build();
  
  configuration.buildSessionFactory(serviceRegistry);
              sessionFactory = new         MetadataSources(serviceRegistry).buildMetadata().buildSessionFactory();
          } catch (Throwable e) {
              log.error(&quot;Unable to setup DB Connection&quot;, e);
          }
      }
  
      public static void closeSession() {
          try {
              final Session s = threadSession.get();
              if ((s != null) &amp;&amp; s.isOpen()) {
                  s.close();
              }
          } catch (final HibernateException ex) {
              log.error(&quot;Unable to close current session&quot;, ex);
          } finally {
              threadSession.set(null);
          }
      }
  
      public static Session getCurrentSession() throws PersistenceException {
          Session s = threadSession.get();
          try {
              if (s == null) {
                  s = sessionFactory.openSession();
                  threadSession.set(s);
              }
          }
         catch (final HibernateException ex) {
              throw new PersistenceException(&quot;Unable to get current session&quot;, ex);
          }
  
          return s;
      }
  
      public static SessionFactory getSessionFactory() {
          return sessionFactory;
      }
  
      public static void commitTransaction() {
          threadSession.get().getTransaction().commit();
          threadSession.get().beginTransaction();
      }
  }
  </code></pre>