K
K
Karl Meinhoff2017-04-21 13:29:53
PostgreSQL
Karl Meinhoff, 2017-04-21 13:29:53

Why doesn't Hibernate see the mapping?

persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xmlns="http://java.sun.com/xml/ns/persistence"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
                                 http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
            version="1.0">
    <persistence-unit name="Protium" transaction-type="RESOURCE_LOCAL">
        <properties>
            <property name="hibernate.hbm2ddl.auto" value="update"/>
            <property name="hibernate.connection.provider_class" value="org.hibernate.c3p0.internal.C3P0ConnectionProvider" />
        </properties>
    </persistence-unit>
</persistence>

PAUser.java
package net.protium.modules.pauth.database.orm;

import net.protium.modules.pauth.oauth2.OAuthType;

import javax.persistence.*;


@SuppressWarnings("JpaDataSourceORMInspection")
@Entity
@Table(name = "pauth_users")
public class PAUser {

  //region DisplayType definition
  @Id
  @Column(name = "user_id", nullable = false, unique = true)
  @GeneratedValue(strategy = GenerationType.IDENTITY)
  private Integer id;

  @Column(name = "login", nullable = false, unique = true)
  private String login;

  @Column(name = "email", nullable = false, unique = true)
  private String email;

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

  @Column(name = "first_name")
  private String firstName = "";

  @Column(name = "middle_name")
  private String middleName = "";

  @Column(name = "last_name")
  private String lastName = "";

  @Column(name = "oauth_bind")
  private String oauthBind;

  @Column(name = "oauth_type")
  private OAuthType oauthType;
  //endregion

  public PAUser(String login, String email, String password, String firstName, String middleName, String lastName, String googleBind) {
    this.login = login;
    this.email = email;
    this.password = password;
    this.firstName = firstName;
    this.middleName = middleName;
    this.lastName = lastName;
    this.oauthBind = googleBind;
  }

  public PAUser( ) {
  }

  //region Getters and Setters
  public Integer getId( ) {
    return id;
  }

  public void setId(Integer id) {
    this.id = id;
  }

  public String getLogin( ) {
    return login;
  }

  public void setLogin(String login) {
    this.login = login;
  }

  public String getEmail( ) {
    return email;
  }

  public void setEmail(String email) {
    this.email = email;
  }

  public String getPassword( ) {
    return password;
  }

  public void setPassword(String password) {
    this.password = password;
  }

  public String getFirstName( ) {
    return firstName;
  }

  public void setFirstName(String firstName) {
    this.firstName = firstName;
  }

  public String getMiddleName( ) {
    return middleName;
  }

  public void setMiddleName(String middleName) {
    this.middleName = middleName;
  }

  public String getLastName( ) {
    return lastName;
  }

  public void setLastName(String lastName) {
    this.lastName = lastName;
  }

  public String getOauthBind( ) {
    return oauthBind;
  }

  public void setOauthBind(String googleBind) {
    this.oauthBind = googleBind;
  }

  public OAuthType getOauthType( ) {
    return oauthType;
  }

  public void setOauthType(OAuthType oauthType) {
    this.oauthType = oauthType;
  }

  //endregion
}


When calling this code
TypedQuery < PAUser > query = entityManager
        .createQuery(
          "select user " +
            "from PAUser user " +
            "where user.login=:login",
          PAUser.class);

      System.out.println(query);

      user = query.setParameter("login", login)
        .getSingleResult();

I get this:
org.hibernate.hql.internal.ast.QuerySyntaxException: PAUser is not mapped [select user from PAUser user where user.login=:login]

How so?
UPD:
One detail: all these classes are in a separate JARe, which is dynamically loaded into the main one. And so in the core persistence.xml also lies.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
aol-nnov, 2017-04-21
@KarleKremen

One detail: all these classes are in a separate JARe

www.stackoverflow.com/a/7443665

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question