Note that there are some explanatory texts on larger screens.

plurals
  1. POorg.hibernate.hql.ast.QuerySyntaxException: Product is not mapped [from Product]
    primarykey
    data
    text
    <p>My infuriating problem of the day is this:</p> <p>I'm trying to use Hibernate to access a database. After a number of false starts, I gave up on my specific project and elected to use the sample database and wizards that shipped with Netbeans 6.9.</p> <p>I fired up Netbeans, started the sample Derby database, and followed the instructions in this tutorial: <a href="http://netbeans.org/kb/docs/java/hibernate-java-se.html" rel="nofollow noreferrer">http://netbeans.org/kb/docs/java/hibernate-java-se.html</a>, skipping the bit about the MySQL database and substituting information for the Derby <code>sample</code> database where appropriate.</p> <p>All of my googling tells me that I'm making a rookie mistake and referring to the table name and not the class name. I've convinced myself that this is not the case[1]. There are only so many ways to refer to a class. Other than that, I'm baffled. I've used nothing but the wizards, I've used the sample database, and I can't find anything else I might have screwed up.</p> <p>I right-click on <code>hibernate.cfg.xml</code>, choose <code>Run HQL Query</code> (just like in the tutorial) and get the exception in the question title above when I run the query <code>from Product</code></p> <p>Please help me before my liver gives out.</p> <p>[1] This is where one of you will prove me wrong.</p> <p><strong>hibernate.cfg.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt; &lt;hibernate-configuration&gt; &lt;session-factory&gt; &lt;property name="hibernate.dialect"&gt;org.hibernate.dialect.DerbyDialect&lt;/property&gt; &lt;property name="hibernate.connection.driver_class"&gt;org.apache.derby.jdbc.ClientDriver&lt;/property&gt; &lt;property name="hibernate.connection.url"&gt;jdbc:derby://localhost:1527/sample&lt;/property&gt; &lt;property name="hibernate.connection.username"&gt;app&lt;/property&gt; &lt;property name="hibernate.connection.password"&gt;app&lt;/property&gt; &lt;property name="hibernate.show_sql"&gt;true&lt;/property&gt; &lt;mapping resource="sample/db/PurchaseOrder.hbm.xml"/&gt; &lt;mapping resource="sample/db/Customer.hbm.xml"/&gt; &lt;mapping resource="sample/db/MicroMarket.hbm.xml"/&gt; &lt;mapping resource="sample/db/ProductCode.hbm.xml"/&gt; &lt;mapping resource="sample/db/Product.hbm.xml"/&gt; &lt;mapping resource="sample/db/Manufacturer.hbm.xml"/&gt; &lt;mapping resource="sample/db/DiscountCode.hbm.xml"/&gt; &lt;/session-factory&gt; &lt;/hibernate-configuration&gt; </code></pre> <p><strong>Product.hbm.xml</strong></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"&gt; &lt;!-- Generated Aug 30, 2010 3:57:50 PM by Hibernate Tools 3.2.1.GA --&gt; &lt;hibernate-mapping&gt; &lt;class name="sample.db.Product" schema="APP" table="PRODUCT"&gt; &lt;id name="productId" type="int"&gt; &lt;column name="PRODUCT_ID"/&gt; &lt;generator class="assigned"/&gt; &lt;/id&gt; &lt;property name="manufacturerId" type="int"&gt; &lt;column name="MANUFACTURER_ID" not-null="true"/&gt; &lt;/property&gt; &lt;property name="productCode" type="string"&gt; &lt;column length="2" name="PRODUCT_CODE" not-null="true"/&gt; &lt;/property&gt; &lt;property name="purchaseCost" type="big_decimal"&gt; &lt;column name="PURCHASE_COST" precision="12"/&gt; &lt;/property&gt; &lt;property name="quantityOnHand" type="java.lang.Integer"&gt; &lt;column name="QUANTITY_ON_HAND"/&gt; &lt;/property&gt; &lt;property name="markup" type="big_decimal"&gt; &lt;column name="MARKUP" precision="4"/&gt; &lt;/property&gt; &lt;property name="available" type="string"&gt; &lt;column length="5" name="AVAILABLE"/&gt; &lt;/property&gt; &lt;property name="description" type="string"&gt; &lt;column length="50" name="DESCRIPTION"/&gt; &lt;/property&gt; &lt;/class&gt; &lt;/hibernate-mapping&gt; </code></pre> <p><strong>Product.java</strong></p> <pre><code>package sample.db; // Generated Aug 30, 2010 3:57:50 PM by Hibernate Tools 3.2.1.GA import java.math.BigDecimal; /** * Product generated by hbm2java */ public class Product implements java.io.Serializable { private int productId; private int manufacturerId; private String productCode; private BigDecimal purchaseCost; private Integer quantityOnHand; private BigDecimal markup; private String available; private String description; public Product() { } public Product(int productId, int manufacturerId, String productCode) { this.productId = productId; this.manufacturerId = manufacturerId; this.productCode = productCode; } public Product(int productId, int manufacturerId, String productCode, BigDecimal purchaseCost, Integer quantityOnHand, BigDecimal markup, String available, String description) { this.productId = productId; this.manufacturerId = manufacturerId; this.productCode = productCode; this.purchaseCost = purchaseCost; this.quantityOnHand = quantityOnHand; this.markup = markup; this.available = available; this.description = description; } public int getProductId() { return this.productId; } public void setProductId(int productId) { this.productId = productId; } public int getManufacturerId() { return this.manufacturerId; } public void setManufacturerId(int manufacturerId) { this.manufacturerId = manufacturerId; } public String getProductCode() { return this.productCode; } public void setProductCode(String productCode) { this.productCode = productCode; } public BigDecimal getPurchaseCost() { return this.purchaseCost; } public void setPurchaseCost(BigDecimal purchaseCost) { this.purchaseCost = purchaseCost; } public Integer getQuantityOnHand() { return this.quantityOnHand; } public void setQuantityOnHand(Integer quantityOnHand) { this.quantityOnHand = quantityOnHand; } public BigDecimal getMarkup() { return this.markup; } public void setMarkup(BigDecimal markup) { this.markup = markup; } public String getAvailable() { return this.available; } public void setAvailable(String available) { this.available = available; } public String getDescription() { return this.description; } public void setDescription(String description) { this.description = description; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload