2

I have a J2EE 7 web app running on wildfly 8.2. Database is H2. Here's my entity class

    @MappedSuperclass
    public class AbstractEntity implements Serializable {
        @Id
        @GeneratedValue(strategy = GenerationType.AUTO)
        private Long id;

    //Getters/Setters are here
    }

@Entity
public class Patient extends AbstractEntity {
    private String firstName;
    private String lastName;
    private Date DOB;

    //Setters/Getters are here 
}

persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="patient-pu" transaction-type="JTA">
    <jta-data-source>java:jboss/h2</jta-data-source>
    <class>com.example.backend.Patient</class>
  </persistence-unit>
</persistence>

When I query my entities, I got this error. For some reason, hibernate appened the "0_" to my table name so it can't find the columns. Do you know why?

06:59:18,220 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-19) Column "PATIENT0_.DOB" not found; SQL statement:
select patient0_.id as id1_0_, patient0_.DOB as DOB2_0_, patient0_.firstName as firstNam3_0_, patient0_.lastName as lastName4_0_ from Patient patient0_ [42122-173]
06:59:18,220 ERROR [org.jboss.as.ejb3.invocation] (default task-19) JBAS014134: EJB Invocation failed on component PatientService for method public java.util.List com.example.backend.PatientService.findAll(): javax.ejb.EJBException: javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not prepare statement
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.handleExceptionInOurTx(CMTTxInterceptor.java:190) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.invokeInOurTx(CMTTxInterceptor.java:275) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.required(CMTTxInterceptor.java:340) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.as.ejb3.tx.CMTTxInterceptor.processInvocation(CMTTxInterceptor.java:239) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.CurrentInvocationContextInterceptor.processInvocation(CurrentInvocationContextInterceptor.java:41) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.invocationmetrics.WaitTimeInterceptor.processInvocation(WaitTimeInterceptor.java:43) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.security.SecurityContextInterceptor.processInvocation(SecurityContextInterceptor.java:95) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.ShutDownInterceptorFactory$1.processInvocation(ShutDownInterceptorFactory.java:64) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
    at org.jboss.invocation.InterceptorContext.proceed(InterceptorContext.java:309)
    at org.jboss.as.ejb3.component.interceptors.LoggingInterceptor.processInvocation(LoggingInterceptor.java:59) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
Andy
  • 77
  • 1
  • 12

1 Answers1

3

Really Hibernate is not appending nothing, review the query:

select  patient0_.id as id1_0_,
        patient0_.DOB as DOB2_0_,
        patient0_.firstName as firstNam3_0_,
        patient0_.lastName as lastName4_0_ 
from Patient patient0_ 

You can see that patient0_ is just an alias. The error means that there is no DOB column in your table Patient. Are you sure that there is a DOB column? Maybe there is a problem with the case and there is really dob in lowercase then you must map as following

@Column(name="dob")
private Date DOB;
Ernesto Campohermoso
  • 7,213
  • 1
  • 40
  • 51