Hibernate fetches one more column that is an arbitrary integer - java

I'm seeing this weird console output
Hibernate:
select
simplematc0_.id as id1_74_0_,
simplematc0_.master_id as master_i2_74_0_,
simplematc0_.slave_code as slave_co3_74_0_,
simplematc0_.slave_grade as slave_gr4_74_0_
from
match_slave simplematc0_
where
simplematc0_.id=?
10:07:38,713 TRACE BasicBinder:84 - binding parameter [1] as [BIGINT] - 68
10:07:38,715 TRACE BasicExtractor:74 - Found [0] as column [master_i2_74_0_]
10:07:38,715 TRACE BasicExtractor:74 - Found [test12] as column [slave_co3_74_0_]
10:07:38,715 TRACE BasicExtractor:74 - Found [1] as column [slave_gr4_74_0_]
10:07:38,715 TRACE BasicExtractor:74 - Found [1] as column [slave_gr4_74_0_]
10:07:38,716 TRACE BasicExtractor:74 - Found [1937012087] as column [slave_co3_74_0_]
I queried for 4 columns and Hibernate returns 5 columns. I need the value "test12" but it keeps returning "1937012087" which I could not find in any of my tables.
Why is Hibernate getting this weird value ?
properties.match.master.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="match_master" name="properties.match.SimpleMatchMaster">
<id name="id">
<generator class="sequence">
<param name="sequence">
seq_matching_item_codes_pk
</param>
</generator>
</id>
<property name="masterCode">
<column name="master_code"/>
</property>
<property name="masterName">
<column name="MASTER_NAME"/>
</property>
<property name="masterGrade">
<column name="master_grade"/>
</property>
<property name="isInUse">
<column name="default_in_use_id"></column>
</property>
<many-to-one name="useStatus" class="properties.SimpleIsInUse" fetch="select"
insert="false" update="false" lazy="false" not-null="false" not-found="ignore">
<column name="default_in_use_id"></column>
</many-to-one>
<many-to-one name="masterObject" class="foreign.Mea_class_no"
not-found="ignore" not-null="false" update="false" insert="false"
fetch="select" lazy="false"
>
<column name="master_code"></column>
<column name="master_grade"></column>
</many-to-one>
<set name="matchSlaves" table="jnc_match_master_slave"
order-by="slave_id"
lazy="false" fetch="select" cascade="all, delete-orphan" >
<key column="master_id" ></key>
<many-to-many class="properties.match.SimpleMatchSlave" not-found="ignore"
fetch="select" >
<column name="slave_id"></column>
</many-to-many>
</set>
<set name="matchHistory" table="jnc_match_history"
order-by="history_id" lazy="false" fetch="select"
cascade="all, delete-orphan, delete, persist"
>
<key>
<column name="master_id"></column>
</key>
<many-to-many class="properties.match.SimpleMatchHistory"
foreign-key="master_id"
>
<column name="history_id"></column>
</many-to-many>
</set>
</class>
</hibernate-mapping>
properties.match.slave.hbm.xml
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class table="match_slave" name="properties.match.SimpleMatchSlave"
select-before-update="true"
>
<id name="id" type="long" >
<column name="id" />
<generator class="sequence">
<param name="sequence">seq_match_slave_pk</param>
</generator>
</id>
<property name="masterId" not-null="false">
<column name="master_id"></column>
</property>
<property name="slaveCode" not-null="false">
<column name="slave_code"></column>
</property>
<property name="slaveGrade" not-null="false">
<column name="slave_grade"></column>
</property>
<many-to-one name="slaveObject" class="foreign.Mea_class_no"
fetch="select"
insert="false" update="false" lazy="false" not-found="ignore" not-null="false"
>
<column name="slave_grade"></column>
<column name="slave_code"></column>
</many-to-one>
</class>
</hibernate-mapping>

I've solved it by changing the order of the two columns which were working as a composite foreign key.
Before
<many-to-one name="slaveObject" class="foreign.Mea_class_no"
fetch="select"
insert="false" update="false" lazy="false" not-found="ignore" not-null="false"
>
<column name="slave_grade"></column>
<column name="slave_code"></column>
</many-to-one>
After
<many-to-one name="slaveObject" class="foreign.Mea_class_no"
fetch="select"
insert="false" update="false" lazy="false" not-found="ignore" not-null="false"
>
<column name="slave_code"></column>
<column name="slave_grade"></column>
</many-to-one>

Related

Hibernate pagination ORA-00918: column ambiguously defined

When hibernate tries to paginate an entity generated using the following hbm.xml, it throws up column ambiguously defined.
<class lazy="false" dynamic-update="true" optimistic-lock="all" table="A" name="org.package.Entity">
<cache usage="read-write"/>
<id unsaved-value="null" type="java.lang.Long" name="aId">
<column name="ID_A" not-null="true" sql-type="java.lang.Long"/>
<generator class="org.package.Entity"/>
</id>
<property type="java.lang.Long" name="aGroupId" not-null="true">
<column name="ID_GROUP" not-null="true" sql-type="java.lang.Long"/>
</property>
<property type="java.lang.String" name="statusCode" not-null="true">
<column name="CD_STATUS" not-null="true" sql-type="char(30)" length="30"/>
</property>
<property type="java.lang.Long" name="templateId" not-null="false">
<column name="ID_TEMPLATE" not-null="false" sql-type="java.lang.Long"/>
</property>
<many-to-one name="aGroup" cascade="none" column="Id_Group"
class="org.package.Entity"
insert="false" update="false"/>
<many-to-one name="template" cascade="none" column="ID_TEMPLATE"
class="org.package.Entity"
insert="false" update="false"/>
</class>
What is wrong with this entity definition?
Edit: Turning it into QandA format.
ID_TEMPLATE is being condensed into one column in the query, ID_GROUP isn't.
Hibernate uses a direct string comparison to see if two properties depend on the same column. This is case sensitive, so ID_GROUP was being selected a second time as Id_Group.
Changing the cases to match, it worked.
<class lazy="false" dynamic-update="true" optimistic-lock="all" table="A" name="org.package.Entity">
<cache usage="read-write"/>
<id unsaved-value="null" type="java.lang.Long" name="aId">
<column name="ID_A" not-null="true" sql-type="java.lang.Long"/>
<generator class="org.package.Entity"/>
</id>
<property type="java.lang.Long" name="aGroupId" not-null="true">
<column name="ID_GROUP" not-null="true" sql-type="java.lang.Long"/>
</property>
<property type="java.lang.String" name="statusCode" not-null="true">
<column name="CD_STATUS" not-null="true" sql-type="char(30)" length="30"/>
</property>
<property type="java.lang.Long" name="templateId" not-null="false">
<column name="ID_TEMPLATE" not-null="false" sql-type="java.lang.Long"/>
</property>
<many-to-one name="aGroup" cascade="none" column="ID_GROUP"
class="org.package.Entity"
insert="false" update="false"/>
<many-to-one name="template" cascade="none" column="ID_TEMPLATE"
class="org.package.Entity"
insert="false" update="false"/>
</class>
Maintaining old code is fun. Hope this helps someone.

Hibernate duplicates record along with null value(new row as duplicate) while saving

I am getting following issue while saving entity in hibernate -
It duplicates the record with null values -
(2661956,2601555,'Chloe','Chloe','Thooks',null,null,null,null,null,null,'Y','N','XYZ',to_date('15-NOV-16','DD-MON-RR'),null,null)
with a duplicate -
(2661946,2601555,null,null,null,null,null,null,null,null,null,'Y','N','XYZ',to_date('15-NOV-16','DD-MON-RR'),null,null) -
We have the following mapping -
Parent -
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.sm.persistence.LOADetailBO" table="LOADETAILS">
<id name="loaDetailsId" type="long">
<column name="LOA_ID" precision="38" scale="0"/>
<generator class="com.sm.persistence.dao.seqgen.LOADetailSeqGen">
</generator>
</id>
<many-to-one name="reregistration" class="com.sm.persistence.RerBO" fetch="join">
<column name="RER_ID" precision="38" scale="0"/>
</many-to-one>
<property name="relatedPlanManager" type="string">
<column name="RELATED_PLAN_MANAGER"/>
</property>
<property name="relatedPlanManagerCode" type="string">
<column name="RELATED_PLAN_MANAGER_CODE"/>
</property>
<set name="relatedPlanManagerAddress" inverse="true" cascade="all-delete-orphan">
<key>
<column name="LOA_ID" precision="38" scale="0" not-null="false"/>
</key>
<one-to-many class="com.sm.persistence.AddressBO" />
</set>
<set name="corporateCustomers" inverse="true" cascade="all-delete-orphan">
<key>
<column name="LOA_ID" precision="38" scale="0" not-null="false"/>
</key>
<one-to-many class="com.sm.persistence.CorporateCustomerBO" />
</set>
<set name="privateCustomers" inverse="true" cascade="all-delete-orphan">
<key>
<column name="LOA_ID" precision="38" scale="0" not-null="false" />
</key>
<one-to-many class="com.sm.persistence.PrivateCustomerBO"/>
</set>
<set name="unwrappedAccount" inverse="true" cascade="all-delete-orphan">
<key>
<column name="LOA_ID" precision="38" scale="0" not-null="false"/>
</key>
<one-to-many class="com.sm.persistence.UnwrappedAccountBO" />
</set>
<set name="wrappedAccount" inverse="true" cascade="all-delete-orphan">
<key>
<column name="LOA_ID" precision="38" scale="0" not-null="false" />
</key>
<one-to-many class="com.sm.persistence.WrappedAccountBO"/>
</set>
</class>
</hibernate-mapping>
Child -
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="false">
<class name="com.sm.persistence.PrivateCustomerBO" table="RER_CUSTOMER_DETAIL">
<id name="privateCustomerId" type="long">
<column name="RERE_CUSTOMER_ID" precision="38" scale="0"/>
<generator class="com.sm.persistence.dao.seqgen.PrivateCustomerSeqGen">
</generator>
</id>
<many-to-one name="loaDetail" class="com.sm.persistence.LOADetailBO" fetch="join">
<column name="LOA_DETAILS_ID" precision="38" scale="0"/>
</many-to-one>
<property name="title" type="string">
<column name="TITLE"/>
</property>
<property name="firstName" type="string">
<column name="FIRST_NAME"/>
</property>
<property name="surname" type="string">
<column name="SURNAME"/>
</property>
<set name="address" inverse="false" cascade="all-delete-orphan">
<key>
<column name="PRIVATE_CUSTOMER_ID" precision="38" scale="0" not-null="false"/>
</key>
<one-to-many class="com.sm.persistence.AddressBO" />
</set>
<property name="primary" type="string">
<column name="IS_PRIMARY"/>
</property>
<property name="corporate" type="string">
<column name="IS_CORPORATE"/>
</property>
<!--<property name="dateofBirth" type="string">
<column name="DATE_OF_BIRTH"/>
</property>-->
<property name="nationalInsurance" type="string">
<column name="NINO"/>
</property>
</class>
</hibernate-mapping>
I checked parent object both pre and post save and can't find any object with null value populated. However, when I fetch the object hierarchy with criteria api it returns duplicate record with null.
Please guide.
Quick answer:
PrivateCustomerBO is a child of LOADetailBO. So when your java code
saves a PrivateCustomerBO object it will write to all tables
specified against these 2 objects: RER_CUSTOMER_DETAIL = primary
table for PrivateCustomerBO, LOADETAILS = primary table for
LOADetailBO, plus all tables referenced by these two objects via
many-to-one or one-to-many mappings. CORRECT BEHAVIOUR
Expanding the bolded bit above, LOADetailBO is referenced by
PrivateCustomerBO via:
<many-to-one name="loaDetail" class="com.sm.persistence.LOADetailBO" fetch="join">
<column name="LOA_DETAILS_ID" precision="38" scale="0"/>
</many-to-one>
This means that LOADETAILS is additionally referenced as a related
table, not just a parent and a second row is written (in this case
there is some data missing (NULL) because your program hasn't
populated it for the referenced entity). INCORRECT BEHAVIOUR.
Fix: remove the many-to-one mapping shown above (it's redundant and covered by parent).

Yet another repeated column in hibernate mapping

Hibernate is giving me the following exception
org.hibernate.MappingException: Repeated column in mapping for entity: Pricelist column: ID_OFFER (should be mapped with insert="false" update="false")
but I really cannot find the duplicate reference to ID_OFFER. Here they are the two mapping files involved.
Offer.hbm.xml
<hibernate-mapping>
<class name="Offer" table="OFFERS">
<id name="idOffer" type="java.lang.Long">
<column name="ID_OFFER" not-null="true" precision="10" scale="0"
sql-type="NUMBER" unique="true"/>
<generator class="native">
<param name="sequence">OFFERS_SEQ</param>
</generator>
</id>
<property generated="never" lazy="false" name="name" type="string">
<column name="name" not-null="true" sql-type="VARCHAR2" unique="true"/>
</property>
<set name="pricelists" sort="unsorted" table="PRICELISTS">
<key not-null="true">
<column name="ID_OFFER" not-null="true" precision="10" scale="0" sql-type="NUMBER"/>
</key>
<one-to-many class="Pricelist"/>
</set>
</class>
</hibernate-mapping>
Pricelist.hbm.xml
<hibernate-mapping>
<class name="Pricelist" table="PRICELISTS">
<id name="idPricelist" type="java.lang.Long">
<column name="ID_PRICELIST" not-null="true" precision="10" scale="0" sql-type="NUMBER"/>
<generator class="native">
<param name="sequence">PRICELISTS_SEQ</param>
</generator>
</id>
<property name="name" type="string">
<column length="255" name="NAME" not-null="true" sql-type="VARCHAR2"/>
</property>
<property name="versionMajor" type="integer">
<column name="VERSION_MAJOR" not-null="true" precision="5" scale="0" sql-type="NUMBER"/>
</property>
<property name="versionMinor" type="integer">
<column name="VERSION_MINOR" not-null="true" precision="5" scale="0" sql-type="NUMBER"/>
</property>
<many-to-one class="Offer" name="offer">
<column name="ID_OFFER" not-null="true" precision="10" scale="0" sql-type="NUMBER"/>
</many-to-one>
<many-to-one class="PricelistStatus" name="status">
<column name="ID_STATUS_PRICELIST" not-null="true" precision="10"
scale="0" sql-type="NUMBER"/>
</many-to-one>
<property name="validFrom" type="calendar">
<column name="INIT_TIMESTAMP" not-null="true" scale="6" sql-type="TIMESTAMP"/>
</property>
<property name="validUntil" type="calendar">
<column name="END_TIMESTAMP" not-null="false" scale="6" sql-type="TIMESTAMP"/>
</property>
</class>
</hibernate-mapping>
I am going crazy. Can anybody see where is it supposed to be duplicated the reference to the column ID_OFFER? Please note: two tables of my schema have a column named like that: OFFERS.ID_OFFER, which is the primary key of the table OFFERS and PRICELIST.ID_OFFER which has a foreign key constraint referencing, obviously, OFFERS.ID_OFFER.
You forgot about map this column as owning side (Offer.hbm.xml file)
<set name="pricelists" sort="unsorted" table="PRICELISTS">
<key not-null="true">
<column name="ID_OFFER" not-null="true" precision="10" scale="0" sql-type="NUMBER"/>
</key>
<one-to-many class="Pricelist"/>
</set>
it should look like (look at inverse="true"):
<set name="pricelists" sort="unsorted" table="PRICELISTS" inverse="true">
<key not-null="true">
<column name="ID_OFFER" not-null="true" precision="10" scale="0" sql-type="NUMBER"/>
</key>
<one-to-many class="Pricelist"/>
</set>
What #zxcf said, actually made the exception disappear, but made another question appear in my mind. Why doesn't the following mapping creates the same problem?
ServiceElement.hbm.xml
<hibernate-mapping>
<class name="ServiceElement" table="SERVICE_ELEMENTS">
<id name="idServiceElement" type="java.lang.Long">
<column name="ID_SERVICE_ELEMENT" not-null="true" precision="10"
scale="0" sql-type="NUMBER" unique="true"/>
<generator class="native">
<param name="sequence">SERVICE_ELEMENTS_SEQ</param>
</generator>
</id>
<set name="prices" table="PRICES">
<key>
<column name="ID_SERVICE_ELEMENT" not-null="true" precision="10"
scale="0" sql-type="NUMBER"/>
</key>
<one-to-many class="Price"/>
</set>
</class>
</hibernate-mapping>
Price.hbm.xml
<hibernate-mapping>
<class name="Price" table="PRICES">
<id name="idPrice" type="java.lang.Long">
<column name="ID_PRICE" not-null="true" precision="10" scale="0"
sql-type="NUMBER" unique="true"/>
<generator class="native">
<param name="sequence">PRICES_SEQ</param>
</generator>
</id>
<many-to-one class="ServiceElement" name="serviceElement">
<column name="ID_SERVICE_ELEMENT" not-null="true" precision="10"
scale="0" sql-type="NUMBER"/>
</many-to-one>
</class>
</hibernate-mapping>
Isn't it the exact same mapping? But it does not throw any exception. Here they go the DDLs:
CREATE TABLE "CE_PRICELIST"."OFFERS"
( "ID_OFFER" NUMBER(10,0),
"NAME" VARCHAR2(255 CHAR));
CREATE UNIQUE INDEX "CE_PRICELIST"."OFFERS_PK" ON "CE_PRICELIST"."OFFERS" ("ID_OFFER");
ALTER TABLE "CE_PRICELIST"."OFFERS" ADD CONSTRAINT "OFFERS_PK" PRIMARY KEY ("ID_OFFER");
CREATE TABLE "CE_PRICELIST"."PRICELISTS"
( "ID_PRICELIST" NUMBER(10,0),
"ID_OFFER" NUMBER(10,0));
CREATE UNIQUE INDEX "CE_PRICELIST"."PRICELISTS_PK" ON "CE_PRICELIST"."PRICELISTS" ("ID_PRICELIST");
ALTER TABLE "CE_PRICELIST"."PRICELISTS" ADD CONSTRAINT "PRICELISTS_PK" PRIMARY KEY ("ID_PRICELIST");
ALTER TABLE "CE_PRICELIST"."PRICELISTS" ADD CONSTRAINT "PRICELISTS_OFFER_ID_FK" FOREIGN KEY ("ID_OFFER") REFERENCES "CE_PRICELIST"."OFFERS" ("ID_OFFER") ENABLE;
CREATE TABLE "CE_PRICELIST"."SERVICE_ELEMENTS"
( "ID_SERVICE_ELEMENT" NUMBER(10,0));
CREATE UNIQUE INDEX "CE_PRICELIST"."SERVICE_ELEMENTS_PK" ON "CE_PRICELIST"."SERVICE_ELEMENTS" ("ID_SERVICE_ELEMENT");
ALTER TABLE "CE_PRICELIST"."SERVICE_ELEMENTS" ADD CONSTRAINT "SERVICE_ELEMENTS_PK" PRIMARY KEY ("ID_SERVICE_ELEMENT");
CREATE TABLE "CE_PRICELIST"."PRICES"
( "ID_PRICE" NUMBER(10,0),
"ID_SERVICE_ELEMENT" NUMBER(10,0));
CREATE UNIQUE INDEX "CE_PRICELIST"."PRICES_PK" ON "CE_PRICELIST"."PRICES" ("ID_PRICE");
ALTER TABLE "CE_PRICELIST"."PRICES" ADD CONSTRAINT "PRICES_SERVICE_ELEMENT_ID_FK" FOREIGN KEY ("ID_SERVICE_ELEMENT")
REFERENCES "CE_PRICELIST"."SERVICE_ELEMENTS" ("ID_SERVICE_ELEMENT") ENABLE;
OFFERS has a PK on ID_OFFER, which is referenced by PRICELISTS.ID_OFFER; Offer has a Set< Pricelist >;
SERVICE_ELEMENTS has a PK on ID_SERVICE_ELEMENT, which is referenced by PRICES.ID_SERVICE_ELEMENT; ServiceElement has a Set< Price >;
So why is the inverse attribute needed in one case and not in another one?

Error When writing Hibernate HQL

I'm testing the following hql but getting an error
String SQL="From Bid bid where bid.Auction.AuctionId=3655"
Class Bid Mapping File:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Jan 19, 2011 5:25:35 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="com.BiddingSystem.Models.Bid" table="BID">
<id name="BidId" type="long">
<column name="BIDID" />
<generator class="native" />
</id>
<property name="BidAmount" type="long">
<column name="BIDAMOUNT" />
</property>
<many-to-one name="User" class="com.BiddingSystem.Models.Users" fetch="join">
<column name="UserId" />
</many-to-one>
<many-to-one name="auction" class="com.BiddingSystem.Models.Auction" fetch="join" lazy="false">
<column name="AuctionId" />
</many-to-one>
<property name="TimePosted" type="java.util.Date" access="field">
<column name="TIMEPOSTED" />
</property>
</class>
</hibernate-mapping>
Auction Mapping File:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 28, 2010 9:14:12 PM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="com.BiddingSystem.Models.Auction" table="AUCTION">
<id name="AuctionId" type="long">
<column name="AUCTIONID" />
<generator class="native" />
</id>
<property name="StartTime" type="java.util.Date">
<column name="STARTTIME" />
</property>
<property name="EndTime" type="java.util.Date">
<column name="ENDTIME" />
</property>
<property name="DatePlaced" type="java.util.Date">
<column name="DatePlaced" />
</property>
<property name="StartingBid" type="long">
<column name="STARTINGBID" />
</property>
<property name="MinIncrement" type="long">
<column name="MININCREMENT" />
</property>
<many-to-one name="CurrentItem" class="com.BiddingSystem.Models.Item" fetch="join" not-null="true" cascade="all" unique="true" lazy="false">
<column name="CURRENTITEM" />
</many-to-one>
<property name="AuctionStatus" type="java.lang.String">
<column name="AUCTIONSTATUS" />
</property>
<property name="BestBid" type="long">
<column name="BESTBID" />
</property>
<many-to-one name="User" class="com.BiddingSystem.Models.Users" fetch="join">
<column name="UserId" />
</many-to-one>
</class>
</hibernate-mapping>
Error:
Caused by: org.hibernate.QueryException: could not resolve property: Auction of: com.BiddingSystem.Models.Bid [From com.BiddingSystem.Models.Bid bid where bid.Auction.AuctionId=3655 and bid.User.UserId=3657]
at org.hibernate.persister.entity.AbstractPropertyMapping.propertyException(AbstractPropertyMapping.java:81)
at org.hibernate.persister.entity.AbstractPropertyMapping.toType(AbstractPropertyMapping.java:75)
at org.hibernate.persister.entity.AbstractEntityPersister.toType(AbstractEntityPersister.java:1449)
at org.hibernate.hql.ast.tree.FromElementType.getPropertyType(FromElementType.java:315)
at org.hibernate.hql.ast.tree.FromElement.getPropertyType(FromElement.java:487)
at org.hibernate.hql.ast.tree.DotNode.getDataType(DotNode.java:611)
at org.hibernate.hql.ast.tree.DotNode.prepareLhs(DotNode.java:263)
at org.hibernate.hql.ast.tree.DotNode.resolve(DotNode.java:210)
at org.hibernate.hql.ast.tree.DotNode.resolveFirstChild(DotNode.java:175)
at org.hibernate.hql.ast.HqlSqlWalker.lookupProperty(HqlSqlWalker.java:571)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.addrExpr(HqlSqlBaseWalker.java:4774)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1326)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.exprOrSubquery(HqlSqlBaseWalker.java:4471)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.comparisonExpr(HqlSqlBaseWalker.java:3944)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:2047)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.logicalExpr(HqlSqlBaseWalker.java:1972)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.whereClause(HqlSqlBaseWalker.java:831)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:617)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:254)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:185)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:136)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:101)
at org.hibernate.engine.query.HQLQueryPlan.<init>(HQLQueryPlan.java:80)
at org.hibernate.engine.query.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:124)
at org.hibernate.impl.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:156)
at org.hibernate.impl.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:135)
at org.hibernate.impl.SessionImpl.createQuery(SessionImpl.java:1770)
at com.BiddingSystem.server.ServiceImpl.getBid(ServiceImpl.java:1463)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sf.gilead.gwt.PersistentRemoteService.processCall(PersistentRemoteService.java:174)
Based on your Bid mapping file, your SQL should be like this:-
String SQL="From Bid bid where bid.auction.AuctionId=3655"
But seriously, your camel-casing in your beans are really messed up. Property names in your bean SHOULD begin with small letter first (ex: auctionId, auction, timePosted, etc).
I bet this will work
String SQL="From Bid bid where bid.auction.auctionId=3655"
Properties are supposed to always start with lowercase characters in java.

Placing List Index when using List in Hibernate

I was using a Set but now due to a widget restriction, I need to use a list.a
a sample of my mapping file using A SET and a List are as follows. Can someone help me to place the list index. I am getting some confusion.
**Attribute Mapping File using Set**
?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 5:25:09 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="native" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<set name="Options" table="ATTRIBUTEOPTION" inverse="false" cascade="all" lazy="true">
<key>
<column name="ATTRIBUTEID" />
</key>
<one-to-many class="h.AttributeOption" />
</set>
</class>
</hibernate-mapping>
**Category Mapping File using Set**
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 16, 2010 8:37:02 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="native" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>
<many-to-one name="ParentCategory" class="h.Category">
<column name="PARENT_CATEGORY_ID" />
</many-to-one>
<set name="SubCategory" lazy="true" cascade="all-delete-orphan" inverse="true">
<key>
<column name="PARENT_CATEGORY_ID" />
</key>
<one-to-many class="h.Category" />
</set>
<set name="AllAttributes" table="ATTRIBUTE" inverse="false" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<one-to-many class="h.Attribute" />
</set>
</class>
</hibernate-mapping>
Category Mapping File using list without the list index
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Category" table="CATEGORY">
<id name="CategoryId" type="long">
<column name="CATEGORYID" />
<generator class="assigned" />
</id>
<property name="CategoryName" type="java.lang.String">
<column name="CATEGORYNAME" />
</property>
<many-to-one name="ParentCategory" class="h.Category" fetch="join">
<column name="PARENTCATEGORY" />
</many-to-one>
<list name="SubCategory" inverse="false" table="CATEGORY" lazy="true">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Category" />
</list>
<list name="AllAttributes" inverse="false" table="ATTRIBUTE" lazy="true" cascade="all">
<key>
<column name="CATEGORYID" />
</key>
<list-index></list-index>
<one-to-many class="h.Attribute" />
</list>
</class>
</hibernate-mapping>
Attribute Mapping File using list with not list index
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Dec 17, 2010 2:10:50 AM by Hibernate Tools 3.4.0.Beta1 -->
<hibernate-mapping>
<class name="h.Attribute" table="ATTRIBUTE">
<id name="AttributeId" type="long">
<column name="ATTRIBUTEID" />
<generator class="assigned" />
</id>
<property name="AttributeName" type="java.lang.String">
<column name="ATTRIBUTENAME" />
</property>
<list name="Options" inverse="false" table="ATTRIBUTEOPTION" lazy="true" cascade="all">
<key>
<column name="ATTRIBUTEID" />
</key>
<list-index></list-index>
<one-to-many class="h.AttributeOption" />
</list>
</class>
</hibernate-mapping>
Read Hibernate Reference: 6.2.3. Indexed collections
For Example:
<list name="whatEver">
<key column="whatEver_fk"/>
<index column="idx"/>
<one-to-many class="WhatEver"/>
</list>
The Hibernate 3.3 reference says "The index of an array or list is always of type integer...", and also "If your table does not have an index column, and you still wish to use list as the property type, you can map the property as a Hibernate <bag>."
A example of bag:
<bag name="options" table="ATTRIBUTEOPTION" order-by="column_name asc|desc" inverse="true" lazy="true" fetch="select">
<key column="ATTRIBUTEID" />
<one-to-many class="h.AttributeOption" />
</bag>
I think you should give "index" property in POJO for which you are creating one-to-many relation
<list name="whatEver">
<key column="whatEver_fk"/>
<index column="idx"/>
<one-to-many class="WhatEver_Class"/>
</list>
In above example , "WhatEver_Class" POJO should have a index property , and it's hbm file should have below property tag.
<property name="index" type="long" insert="false" update="false">
<column name="idx" />
</property>

Categories