views:

26

answers:

1

My infuriating problem of the day is this:

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.

I fired up Netbeans, started the sample Derby database, and followed the instructions in this tutorial: http://netbeans.org/kb/docs/java/hibernate-java-se.html, skipping the bit about the MySQL database and substituting information for the Derby sample database where appropriate.

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.

I right-click on hibernate.cfg.xml, choose Run HQL Query (just like in the tutorial) and get the exception in the question title above when I run the query from Product

Please help me before my liver gives out.

[1] This is where one of you will prove me wrong.

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"&gt;
 <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/sample</property>
    <property name="hibernate.connection.username">app</property>
    <property name="hibernate.connection.password">app</property>
<property name="hibernate.show_sql">true</property>
<mapping resource="sample/db/PurchaseOrder.hbm.xml"/>
<mapping resource="sample/db/Customer.hbm.xml"/>
<mapping resource="sample/db/MicroMarket.hbm.xml"/>
<mapping resource="sample/db/ProductCode.hbm.xml"/>
<mapping resource="sample/db/Product.hbm.xml"/>
<mapping resource="sample/db/Manufacturer.hbm.xml"/>
<mapping resource="sample/db/DiscountCode.hbm.xml"/>
  </session-factory>
</hibernate-configuration>

Product.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"&gt;
<!-- Generated Aug 30, 2010 3:57:50 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
  <class name="sample.db.Product" schema="APP" table="PRODUCT">
    <id name="productId" type="int">
      <column name="PRODUCT_ID"/>
      <generator class="assigned"/>
    </id>
    <property name="manufacturerId" type="int">
      <column name="MANUFACTURER_ID" not-null="true"/>
    </property>
    <property name="productCode" type="string">
      <column length="2" name="PRODUCT_CODE" not-null="true"/>
    </property>
    <property name="purchaseCost" type="big_decimal">
      <column name="PURCHASE_COST" precision="12"/>
    </property>
    <property name="quantityOnHand" type="java.lang.Integer">
      <column name="QUANTITY_ON_HAND"/>
    </property>
    <property name="markup" type="big_decimal">
      <column name="MARKUP" precision="4"/>
    </property>
    <property name="available" type="string">
      <column length="5" name="AVAILABLE"/>
    </property>
    <property name="description" type="string">
      <column length="50" name="DESCRIPTION"/>
    </property>
  </class>
</hibernate-mapping>

Product.java

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;
    }




}
A: 

The Netbeans HQL Query runner seems to be broken. I followed Pascal Thivent's advice and everything works fine.

If anyone else finds themselves having the same problem and comes up with a fix, post it here and I'll mark it as the answer.

Dave