- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有示例 Web 应用程序 Hibernate 4.3.5 + Derby 数据库 10.10.1.1+ Glassfish4.0 和 IDE NetBeans 8.0Beta。
我有下一个异常(exception):
Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: CUSTOMERV is not mapped
at org.hibernate.hql.internal.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:189)
at org.hibernate.hql.internal.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:109)
at org.hibernate.hql.internal.ast.tree.FromClause.addFromElement(FromClause.java:95)
at org.hibernate.hql.internal.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:331)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3633)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:3522)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:706)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:562)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:299)
at org.hibernate.hql.internal.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:247)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:278)
at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:206)
... 72 more
来自 index.xhtml 的表单
<h:panelGrid id="panel1" columns="2" border="1"
cellpadding="5" cellspacing="1">
<f:facet name="header">
<h:outputText value="Add Customer Information"/>
</f:facet>
<h:outputLabel value="First Name:"/>
<h:inputText value="#{customer.firstName}" id="fn"/>
<h:outputLabel value="Last Name:"/>
<h:inputText value="#{customer.lastName}" id="ln"/>
<h:outputLabel value="Email:"/>
<h:inputText value="#{customer.email}" id="eml"/>
<h:outputLabel value="Date of Birth:"/>
<h:inputText value="#{customer.sd}" id="s"/>
<f:facet name="footer">
<h:outputLabel value="#{customer.msg}" id="msg" styleClass="msg"/>
<h:commandButton value="Save" action="#{customer.saveCustomer}">
</h:commandButton>
</f:facet>
</h:panelGrid>
Customer.java
package com.javaknowledge.entity;
import com.javaknowledge.dao.CustomerDao;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.persistence.*;
@ManagedBean
@SessionScoped
public class Customer implements java.io.Serializable {
private Integer custId;
private String firstName;
private String lastName;
private String email;
private Date dob;
private String sd, msg, selectedname;
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
public Customer() {
}
public Customer(String firstName, String lastName, String email, Date dob) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
this.dob = dob;
}
public String getSd() {
return sd;
}
public void setSd(String sd) {
this.sd = sd;
}
public Integer getCustId() {
return this.custId;
}
public void setCustId(Integer custId) {
this.custId = custId;
}
public String getFirstName() {
return this.firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return this.lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
@Column(name = "EMAIL")
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name = "DOB")
public Date getDob() {
return this.dob;
}
public void setDob(Date dob) {
this.dob = dob;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String getSelectedname() {
return selectedname;
}
public void setSelectedname(String selectedname) {
this.selectedname = selectedname;
}
public void saveCustomer() {
try {
Date d = sdf.parse(sd);
System.out.println(d);
this.dob = d;
} catch (ParseException e) {
e.printStackTrace();
}
CustomerDao dao = new CustomerDao();
dao.addCustomer(this);
this.msg = "Member Info Saved Successfull!";
clearAll();
}
public void updateCustomer() {
try {
Date d = sdf.parse(sd);
System.out.println(d);
this.dob = d;
} catch (ParseException e) {
e.printStackTrace();
}
CustomerDao dao = new CustomerDao();
dao.updateCustomer(this);
this.msg = "Member Info Update Successfull!";
clearAll();
}
public void deleteCustomer() {
CustomerDao dao = new CustomerDao();
dao.deleteCustomer(custId);
this.msg = "Member Info Delete Successfull!";
clearAll();
}
public List<Customer> getAllCustomers() {
List<Customer> users = new ArrayList<Customer>();
CustomerDao dao = new CustomerDao();
users = dao.getAllCustomers();
return users;
}
public void fullInfo() {
CustomerDao dao = new CustomerDao();
List<Customer> lc = dao.getCustomerById(selectedname);
System.out.println(lc.get(0).firstName);
this.custId = lc.get(0).custId;
this.firstName = lc.get(0).firstName;
this.lastName = lc.get(0).lastName;
this.email = lc.get(0).email;
this.dob = lc.get(0).dob;
this.sd = sdf.format(dob);
}
private void clearAll() {
this.firstName = "";
this.lastName = "";
this.sd = "";
this.email = "";
this.custId=0;
}
}
hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
<property name="hibernate.connection.driver_class">org.apache.derby.jdbc.ClientDriver</property>
<property name="hibernate.connection.url">jdbc:derby://localhost:1527/derbyDB</property>
<property name="hibernate.connection.username">user1</property>
<property name="hibernate.connection.password">user1</property>
<property name="hibernate.hbm2ddl.auto">create</property>
<property name="c3p0.min_size">1</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.timeout">300</property>
<property name="c3p0.max_statements">50</property>
<property name="c3p0.idle_test_period">300</property>
<mapping class="com.javaknowledge.entity.Customer" resource="com/javaknowledge/entity/Customer.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Customer.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="com.javaknowledge.entity.Customer" table="CUSTOMERV" schema="APP">
<id name="custId" type="java.lang.Integer">
<column name="cust_id" />
<generator class="increment" />
</id>
<property name="firstName" type="string">
<column name="first_name" length="45" not-null="true" />
</property>
<property name="lastName" type="string">
<column name="last_name" length="45" not-null="true" />
</property>
<property name="email" type="string">
<column name="email" length="45" not-null="true" />
</property>
<property name="dob" type="date">
<column name="dob" length="10" not-null="true" />
</property>
</class>
</hibernate-mapping>
最佳答案
我终于发现了一个错误!希望这对某人有用。向数据库发出请求时(在我的例子中是 Apache Derby),base 的名称需要写第一个大写字母,其他小写。
这是错误的查询:
session.createQuery("select first_name from CUSTOMERV").
这是有效的查询
session.createQuery("select first_name from Customerv").
并且类实体必须与数据库同名,但我不确定。
关于java - org.hibernate.hql.internal.ast.QuerySyntaxException : table is not mapped,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23018836/
我有一个像这样的 UserAssignmentRole 类: @Data @Entity public class UserAssignmentRole { ... @Enumerat
尝试从 Java 服务层进行简单的选择,这是我的模型: import java.io.Serializable; import javax.persistence.Column; import jav
我有以下类(class): public class MyClass { private List _myList = new List(); public virtual strin
当我尝试使用 Hibernate 创建任何数据库查询时,我犯了同样的错误: Error code 道法: @Override public List findAll() { openCurre
我正在关注这个Tutorial 。我添加了另一个 DAO,用于检索 admin_roles 表。该方法如下所示 public List findAllAdminRoleByUserName(Strin
我目前正在从事一个实用程序项目,该项目将帮助我管理应用程序的用户(一个用户有一个或多个角色,一个角色有一个或多个权限)。我是 Hibernate 的新手,不知道为什么会遇到以下问题: ERROR [h
我目前正在从事一个实用程序项目,该项目将帮助我管理应用程序的用户(一个用户有一个或多个角色,一个角色有一个或多个权限)。我是 Hibernate 的新手,不知道为什么会遇到以下问题: ERROR [h
当我尝试执行下一个 HQL 查询时,出现下一个错误: org.hibernate.hql.internal.ast.QuerySyntaxException: Unable to locate app
我已经创建了一个 Hibernate 配置 maven 项目(使用 maven-shade-plugin 构建)以允许我的代码库使用一个统一的“数据库类”。但是,当从正在运行的项目外部调用时,该类似乎
是的,我知道有一些关于此错误的帖子,但没有一个对我有帮助。我的 hql 查询出现此错误: @SuppressWarnings("unchecked") @Override public List ge
我用 spring-boot 开始了一个新项目,以 MySQL 作为数据库系统。但是当我从数据库中读取数据时,我得到了 org.hibernate.hql.internal.ast.QuerySynt
我查询了 3 个具有 HQL 类的表。存在一些一对多的关系。 我的数据库或我的实体类都没有问题.. 我有一些 hibernate DAO 类查询,除了这个以外其他都很好.. jasperreport
我一直在玩一个非常简单的 JPA 示例,并试图将其调整为现有数据库。但我无法克服这个错误。 (下。)它只是一些我没有看到的简单的东西。 org.hibernate.hql.internal.ast.Q
我从前端发送一个值来搜索我的实体 Producto 的两个属性。该属性是Codigo 和Description。 问题是当 TypedQuery typedQuery = em.createQuery
完整错误消息: 11:49:51,896 INFO [stdout] (http-localhost-127.0.0.1-8080-1) javax.ejb.EJBException: java.la
我是 JPA 新手,正在尝试创建 EJB 3.0 + JPA( hibernate )应用程序。当我将数据持久保存到数据库时出现异常。 sessionBean方法: @PersistenceC
我的Spring数据查询是: @Query("FROM NewsFeed nf where dealRoom.id =:dealRoomId and (fileFolder IN :folders o
我收到这个错误: Caused by: javax.ejb.EJBException: java.lang.IllegalArgumentException: org.hibernate.hql.in
在使用 Hibernate 构建查询时,我注意到一些相当奇怪的事情。如果我为 ORDER BY 子句使用顺序命名参数,Hibernate 会抛出一个 QuerySyntaxException(冒号前缀
我收到一个错误,如下所示: java.lang.IllegalArgumentException: org.hibernate.hql.ast.QuerySyntaxException: Direct
我是一名优秀的程序员,十分优秀!