我在wildfly 8.2上运行了一个J2EE 7 Web应用程序。数据库是H2。这是我的实体类
@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>
当我查询我的实体时,我收到了这个错误。出于某种原因,hibernate将“0_”添加到我的表名中,因此无法找到列。你知道为什么吗?
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]
答案 0 :(得分:3)
真的Hibernate没有附加任何内容,请查看查询:
select patient0_.id as id1_0_,
patient0_.DOB as DOB2_0_,
patient0_.firstName as firstNam3_0_,
patient0_.lastName as lastName4_0_
from Patient patient0_
你可以看到patient0_只是一个别名。该错误表示您的表Patient中没有DOB列。你确定有DOB专栏吗?也许这个案例有问题,并且有小写的dob,那么你必须映射如下
@Column(name="dob")
private Date DOB;