1

We are implementing Jersey 2.26 in our application and facing issues with EntityManager. We are using JPA and the persistence classes are packaged in a separate jar.

Took reference from below link:- How do I properly configure an EntityManager in a jersey / hk2 application?

We are able to run Native queries like :

em.createNativeQuery("select employee_name from employee where employee_id = 2406")
  .getSingleResult();

But

em.find(Employee.class,2406)

is giving below error:-

org.hibernate.UnknownEntityTypeException: Unable to locate persister:

persistence.xml

<persistence-unit name="TestPersistence" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
    <jta-data-source>java:jboss/datasources/TestPersistenceDS</jta-data-source>
    <properties>
        <property name="hibernate.cache.provider_class" 
                  value="org.hibernate.cache.NoCacheProvider" />
        <property name="hibernate.connection.driver_class" 
                  value="com.sybase.jdbc4.jdbc.SybDriver" />
        <property name="hibernate.dialect" 
                  value="org.hibernate.dialect.SybaseDialect" />

Entity Employee

@Entity
@Table(name = "employee")
public class Employee implements Serializable {

  private static final long serialVersionUID = 1L;

  @Id
  @Column(name = "emp_id")
  private Long empId;

  @Column(name = "emp_name")
  private String empName;

public Long getEmpId() {
    return empId;
}

public void setEmpId(Long empId) {
    this.empId = empId;
}

public String getEmpName() {
    return empName;
}

public void setEmpName(String empName) {
    this.empName = empName;
}

Any help would be appreciated.

Note: not using maven or spring. the application is deployed on wildfdly 11

pirho
  • 11,565
  • 12
  • 43
  • 70
gari004
  • 11
  • 3

1 Answers1

0

We are using JPA and the persistence classes are packaged in a separate jar.

I think you need to tell in persistence.xml about the jar where the entites are, something like

...
<jta-data-source>java:jboss/datasources/TestPersistenceDS</jta-data-source>
<jar-file>../lib/a-separate.jar</jar-file>
...

NOTE: Depending on the runtime environment path may vary and also the entities in the jar might be required to be enhanced.

pirho
  • 11,565
  • 12
  • 43
  • 70