Hi, I just started using hibernate and am using Middlegen to connect to my database and generate my hbm config files for my tables. Now some tables are working and i get data just fine but on a few tables that have composite keys i'm having problems it seems.
Any Ideas?
My database is oracle 9i by the way, im using hibernate 2.1.2
here is the code i'm executing.
Code:
List hosts = session.find("from Host");
for (int i = 0; i < hosts.size(); i++)
{
Host host = (Host) hosts.get(i);
}
Here is the error message i'm getting
Code:
INFO - building session factory
INFO - no JNDI name configured
Hibernate: select host0_.HOST_ID as HOST_ID, host0_.AFFILIATE_ID as AFFILIAT2_, host0_.APP as APP, host0_.BG_COLOR as BG_COLOR, host0_.BG_IMAGE as BG_IMAGE, host0_.PRODUCT_DISCOUNT as PRODUCT_6_, host0_.SHIP_DISCOUNT_TYPE as SHIP_DIS7_, host0_.SHIP_DISCOUNT_AMT as SHIP_DIS8_, host0_.PAGE_HEADER as PAGE_HEA9_, host0_.PRIMARY_URL as PRIMARY10_, host0_.CART_LINK as CART_LINK, host0_.SHIP_TO_STORE as SHIP_TO12_, host0_.FONT_COLOR as FONT_COLOR, host0_.FONT_NAME as FONT_NAME, host0_.BORDER_COLOR as BORDER_15_, host0_.SHOW_UNAVAILABLE as SHOW_UN16_ from affiliate.HOST host0_
Hibernate: select affiliate0_.AFFILIATE_ID as AFFILIAT1_0_, affiliate0_.NAME as NAME0_, affiliate0_.ORDER_NOTIFICATION_EMAIL as ORDER_NO3_0_, affiliate0_.CUSTOMER_COMM_EMAIL as CUSTOMER4_0_, affiliate0_.VENDOR_CUST_ID as VENDOR_C5_0_, affiliate0_.FTP_ID as FTP_ID0_, affiliate0_.SHIP_METHOD as SHIP_MET7_0_, affiliate0_.GIFT_MSG as GIFT_MSG0_, affiliate0_.STATUS as STATUS0_ from affiliate.AFFILIATE affiliate0_ where affiliate0_.AFFILIATE_ID=?
net.sf.hibernate.UnresolvableObjectException: No row with the given identifier exists: 1, of class: com.muze.sphynx.affiliate.hibernate.Affiliate
at net.sf.hibernate.UnresolvableObjectException.throwIfNull(UnresolvableObjectException.java:38)
at net.sf.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1918)
at net.sf.hibernate.type.ManyToOneType.resolveIdentifier(ManyToOneType.java:68)
at net.sf.hibernate.type.EntityType.resolveIdentifier(EntityType.java:215)
at net.sf.hibernate.type.ComponentType.resolveIdentifier(ComponentType.java:389)
at net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:145)
at net.sf.hibernate.type.ManyToOneType.hydrate(ManyToOneType.java:60)
at net.sf.hibernate.type.ComponentType.hydrate(ComponentType.java:371)
at net.sf.hibernate.type.ComponentType.nullSafeGet(ComponentType.java:145)
at net.sf.hibernate.loader.Loader.getKeyFromResultSet(Loader.java:352)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:203)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:950)
at net.sf.hibernate.loader.Loader.list(Loader.java:941)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1512)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1491)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1483)
at Tester.main(Tester.java:26)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
at java.lang.reflect.Method.invoke(Method.java:386)
at com.intellij.rt.execution.application.AppMain.main(Unknown Source)
Process terminated with exit code 0
here is the hbm for one of my tables
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin
http://boss.bekk.no/boss/middlegen/
http://hibernate.sourceforge.net/
-->
<class
name="com.muze.sphynx.affiliate.hibernate.Host"
table="HOST"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="HOST"
</meta>
<composite-id>
<meta attribute="class-description" inherit="false">
@hibernate.id
generator-class="assigned"
</meta>
<key-property
name="hostId"
column="HOST_ID"
type="java.lang.Integer"
length="9"
>
<meta attribute="field-description">
@hibernate.property
column="HOST_ID"
length="9"
</meta>
</key-property>
<!-- bi-directional many-to-one association to AffiliateApp -->
<key-many-to-one
name="affiliateApp"
class="com.muze.sphynx.affiliate.hibernate.AffiliateApp"
>
<meta attribute="field-description">
@hibernate.many-to-one
column="AFFILIATE_ID""
</meta>
<meta attribute="field-description">
@hibernate.many-to-one
column="APP""
</meta>
<column name="AFFILIATE_ID" />
<column name="APP" />
</key-many-to-one>
</composite-id>
<property
name="bgColor"
type="java.lang.String"
column="BG_COLOR"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="BG_COLOR"
length="30"
</meta>
</property>
<property
name="bgImage"
type="java.lang.String"
column="BG_IMAGE"
length="255"
>
<meta attribute="field-description">
@hibernate.property
column="BG_IMAGE"
length="255"
</meta>
</property>
<property
name="productDiscount"
type="java.math.BigDecimal"
column="PRODUCT_DISCOUNT"
not-null="true"
length="11"
>
<meta attribute="field-description">
@hibernate.property
column="PRODUCT_DISCOUNT"
length="11"
not-null="true"
</meta>
</property>
<property
name="shipDiscountType"
type="java.lang.String"
column="SHIP_DISCOUNT_TYPE"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="SHIP_DISCOUNT_TYPE"
length="1"
</meta>
</property>
<property
name="shipDiscountAmt"
type="java.math.BigDecimal"
column="SHIP_DISCOUNT_AMT"
length="11"
>
<meta attribute="field-description">
@hibernate.property
column="SHIP_DISCOUNT_AMT"
length="11"
</meta>
</property>
<property
name="pageHeader"
type="java.lang.String"
column="PAGE_HEADER"
length="75"
>
<meta attribute="field-description">
@hibernate.property
column="PAGE_HEADER"
length="75"
</meta>
</property>
<property
name="primaryUrl"
type="java.lang.String"
column="PRIMARY_URL"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="PRIMARY_URL"
length="100"
</meta>
</property>
<property
name="cartLink"
type="java.lang.String"
column="CART_LINK"
length="200"
>
<meta attribute="field-description">
@hibernate.property
column="CART_LINK"
length="200"
</meta>
</property>
<property
name="shipToStore"
type="java.lang.String"
column="SHIP_TO_STORE"
length="1"
>
<meta attribute="field-description">
@hibernate.property
column="SHIP_TO_STORE"
length="1"
</meta>
</property>
<property
name="fontColor"
type="java.lang.String"
column="FONT_COLOR"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="FONT_COLOR"
length="30"
</meta>
</property>
<property
name="fontName"
type="java.lang.String"
column="FONT_NAME"
length="100"
>
<meta attribute="field-description">
@hibernate.property
column="FONT_NAME"
length="100"
</meta>
</property>
<property
name="borderColor"
type="java.lang.String"
column="BORDER_COLOR"
length="30"
>
<meta attribute="field-description">
@hibernate.property
column="BORDER_COLOR"
length="30"
</meta>
</property>
<property
name="showUnavailable"
type="int"
column="SHOW_UNAVAILABLE"
not-null="true"
length="3"
>
<meta attribute="field-description">
@hibernate.property
column="SHOW_UNAVAILABLE"
length="3"
not-null="true"
</meta>
</property>
<!-- associations -->
</class>
</hibernate-mapping>