0
我目前在一家沒有主應用程序文檔的公司工作,所以我必須在每次必須做的更改中使用嘗試和失敗技術。如何添加新的Java類以便與數據庫進行映射?
此應用程序是在JDK 6和一些輔助工具(如RichFaces和Hibernate)的JSF 1.2上開發的,連接到數據庫引擎MS SQL Server。此刻,我必須添加一個新的選擇,必須從數據庫飼料,但每當我執行下面的代碼行:
return this.entityManager.createQuery("select d from DiagnosticoPrueba d").getResultList();
它顯示了以下錯誤:
org.hibernate.hql.ast.QuerySyntaxException: DiagnosticoPrueba is not mapped [select d from DiagnosticoPrueba d]
我使用的過程添加新的選擇器如下:
我創建了
DIAGNOSTICO
表並插入了相應的數據。爲了證實這些信息,我會告訴你下列句子的結果。SELECT * FROM DIAGNOSTICO;
EXEC sp_columns DIAGNOSTICO;
我創建JavaDiagnosticoPrueba類,將映射DIAGNOSTICO表
package *.entidades; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.Id; import javax.persistence.Table; @Entity (name = "DiagnosticoPrueba") @Table(name = "DIAGNOSTICO") public class DiagnosticoPrueba implements java.io.Serializable { private static final long serialVersionUID = 1L; private int id; private String nombre; public DiagnosticoPrueba() { } public DiagnosticoPrueba(int id, String nombre) { this.id = id; this.nombre = nombre; } @Id @Column(name = "ID", unique = true, nullable = false) public int getId() { return id; } public void setId(int id) { this.id = id; } @Column(name = "NOMBRE", length = 200) public String getNombre() { return nombre; } public void setNombre(String nombre) { this.nombre = nombre; } }
文件hibernate.cfg.xml
不能在申請中找到,但該文件persistence.xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence 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_1_0.xsd" version="1.0">
<persistence-unit name="MY_ENTERPRISE" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>myEnterpriseDataSource</jta-data-source>
<properties>
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect"/>
<property name="hibernate.default_catalog" value="MY_ENTERPRISE"/>
<property name="hibernate.default_schema" value="SCHEMA_MY_ENTERPRISE"/>
<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
<property name="hibernate.ejb.event.post-insert" value="org.hibernate.ejb.event.EJB3PostInsertEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-update" value="org.hibernate.ejb.event.EJB3PostUpdateEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-delete" value="org.hibernate.ejb.event.EJB3PostDeleteEventListener,org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-update" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.pre-collection-remove" value="org.hibernate.envers.event.AuditEventListener"/>
<property name="hibernate.ejb.event.post-collection-recreate" value="org.hibernate.envers.event.AuditEventListener"/>
</properties>
</persistence-unit>
</persistence>
我認爲錯誤是由於沒有從應用程序配置文件中的實體DiagnosticoPrueba
是,我認爲解決方案的關鍵在於myEnterpriseDataSource
。
你會推薦我做什麼?
謝謝!