I have a table in Postgres as follows:
Code:
CREATE TABLE "DrugName"
(
"drugNameID" int8 NOT NULL DEFAULT nextval('public."DrugName_drugNameID_seq"'::text),
"drugName" varchar(100) NOT NULL,
CONSTRAINT "DrugName_PK1" PRIMARY KEY ("drugNameID")
)
WITHOUT OIDS;
ALTER TABLE "DrugName" OWNER TO postgres;
And a DrugName hibernate java class as noted at the bottom of this post.
When I execute the following code:
Code:
Transaction tx = session.beginTransaction();
Criteria crit = session.createCriteria(DrugName.class);
List allRows = crit.list();
I get the following error. Help?
Code:
(cfg.Environment 460 ) Hibernate 3.0
(cfg.Environment 478 ) loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.postgresql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider, hibernate.max_fetch_depth=1, hibernate.cache.use_query_cache=true, hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect, hibernate.connection.username=postgres, hibernate.connection.url=jdbc:postgresql://localhost/test2, hibernate.show_sql=true, hibernate.connection.password=****}
(cfg.Environment 506 ) using CGLIB reflection optimizer
(cfg.Environment 536 ) using JDK 1.4 java.sql.Timestamp handling
(cfg.Configuration 460 ) Mapping resource: com/test/model/testimport/DrugName.hbm.xml
(cfg.HbmBinder 258 ) Mapping class: com.test.model.testimport.DrugName -> DrugName
(cfg.Configuration 460 ) Mapping resource: com/test/model/testimport/DrugAssay.hbm.xml
(cfg.HbmBinder 258 ) Mapping class: com.test.model.testimport.DrugAssay -> DrugAssay
(cfg.Configuration 460 ) Mapping resource: com/test/model/testimport/DrugTestOrder.hbm.xml
(cfg.HbmBinder 258 ) Mapping class: com.test.model.testimport.DrugTestOrder -> DrugTestOrder
(cfg.Configuration 851 ) processing extends queue
(cfg.Configuration 855 ) processing collection mappings
(cfg.Configuration 864 ) processing association property references
(cfg.Configuration 893 ) processing foreign key constraints
(dialect.Dialect 91 ) Using dialect: org.hibernate.dialect.PostgreSQLDialect
(cfg.SettingsFactory 87 ) Maximum outer join fetch depth: 1
(cfg.SettingsFactory 90 ) Default batch fetch size: 1
(cfg.SettingsFactory 94 ) Generate SQL with comments: disabled
(cfg.SettingsFactory 98 ) Order SQL updates by primary key: disabled
(cfg.SettingsFactory 273 ) Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
(ast.ASTQueryTranslatorFactory 21 ) Using ASTQueryTranslatorFactory
(cfg.SettingsFactory 106 ) Query language substitutions: {}
(connection.DriverManagerConnectionProvider 41 ) Using Hibernate built-in connection pool (not for production use!)
(connection.DriverManagerConnectionProvider 42 ) Hibernate connection pool size: 20
(connection.DriverManagerConnectionProvider 45 ) autocommit mode: false
(connection.DriverManagerConnectionProvider 80 ) using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost/test2
(connection.DriverManagerConnectionProvider 86 ) connection properties: {user=postgres, password=****}
(cfg.SettingsFactory 148 ) JDBC batch size: 15
(cfg.SettingsFactory 151 ) JDBC batch updates for versioned data: disabled
(cfg.SettingsFactory 156 ) Scrollable result sets: enabled
(cfg.SettingsFactory 164 ) JDBC3 getGeneratedKeys(): disabled
(transaction.TransactionFactoryFactory 31 ) Using default transaction strategy (direct JDBC transactions)
(transaction.TransactionManagerLookupFactory 33 ) No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
(cfg.SettingsFactory 176 ) Automatic flush during beforeCompletion(): disabled
(cfg.SettingsFactory 179 ) Automatic session close at end of transaction: disabled
(cfg.SettingsFactory 260 ) Cache provider: org.hibernate.cache.EhCacheProvider
(cfg.SettingsFactory 187 ) Second-level cache: enabled
(cfg.SettingsFactory 192 ) Optimize cache for minimal puts: disabled
(cfg.SettingsFactory 199 ) Structured second-level cache entries: enabled
(cfg.SettingsFactory 203 ) Query cache: enabled
(cfg.SettingsFactory 247 ) Query cache factory: org.hibernate.cache.StandardQueryCacheFactory
(cfg.SettingsFactory 210 ) Echoing all SQL to stdout
(cfg.SettingsFactory 214 ) Statistics: disabled
(cfg.SettingsFactory 218 ) Deleted entity synthetic identifier rollback: disabled
(cfg.SettingsFactory 232 ) Default entity-mode: pojo
(impl.SessionFactoryImpl 140 ) building session factory
(config.Configurator 126 ) No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/eclipse/ims-workspace/TestImport/buildoutput/dist/lib/ehcache-1.1.jar!/ehcache-failsafe.xml
(impl.SessionFactoryObjectFactory 82 ) Not binding factory to JNDI, no JNDI name configured
(cache.UpdateTimestampsCache 43 ) starting update timestamps cache at region: org.hibernate.cache.UpdateTimestampsCache
(cache.EhCacheProvider 97 ) Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults.
(cache.StandardQueryCache 50 ) starting query cache at region: org.hibernate.cache.StandardQueryCache
(cache.EhCacheProvider 97 ) Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults.
(impl.SessionFactoryImpl 366 ) Checking 0 named queries
Hibernate: select this_.drugNameID as drugNameID0_, this_.drugName as drugName0_0_ from DrugName this_
(util.JDBCExceptionReporter 57 ) SQL Error: 0, SQLState: 42P01
(util.JDBCExceptionReporter 58 ) ERROR: relation "drugname" does not exist
Caught exception: could not execute query
-----------------------
Here's the DrugName.xbm.xml file:
Code:
<?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.test.model.testimport.DrugName"
table="DrugName"
>
<id
name="drugNameID"
column="drugNameID"
type="java.lang.Long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-DrugName.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>
<property
name="drugName"
type="java.lang.String"
update="true"
insert="true"
column="drugName"
length="100"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-DrugName.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
-----------------------
Here's the DrugName.java file:
Code:
package com.test.model.testimport;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import com.test.model.common.BasePersistentDO;
/**
* This persistent class represents each individual drug name
* @hibernate.class table="DrugName"
*/
public class DrugName extends BasePersistentDO {
private Long drugNameID;
private String drugName;
/**
* Default Constructor
*/
public DrugName() {
}
/**
* Explicit constructor
* @param drugNameID the ID associated with the drug name
* @param drugName the name of the drug
*/
public DrugName(String drugName) {
this.drugName = drugName;
}
/**
* Gets the id of the drug name
* @return the drug name ID
* @hibernate.id generator-class="native"
*/
public Long getDrugNameID() {
return drugNameID;
}
/**
* Sets the id of the drug name
* @param drugNameID the id of the drug name
*/
public void setDrugNameID(Long drugNameID) {
this.drugNameID = drugNameID;
}
/**
* Gets the name of the drug
* @return the drug name
* @hibernate.property length="100"
*/
public String getDrugName() {
return drugName;
}
/**
* Sets the name of the drug
* @param drugName the drug name
*/
public void setDrugName(String drugName) {
this.drugName = drugName;
}
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (!(other instanceof DrugName)) {
return false;
}
DrugName otherDrugName = (DrugName) other;
EqualsBuilder eq = new EqualsBuilder().appendSuper(super.equals(other)).append(getDrugNameID(),
otherDrugName.getDrugNameID());
return eq.isEquals();
}
public int hashCode() {
return new HashCodeBuilder(getMultiplierPrime(this), getNonZeroOddPrime(this)).append(getId()).append(getDrugNameID())
.toHashCode();
}
}