-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Load with composite id
PostPosted: Tue Oct 19, 2004 7:39 am 
Newbie

Joined: Tue Oct 19, 2004 7:09 am
Posts: 2
Location: S
Hibernate version: 2.1.6

Mapping documents:
<class
name="com.probel.fatura.data.VendedorClientePO"
table="vendas.VENDEDOR_CLIENTE"
>

<composite-id name="comp_id" class="com.probel.fatura.data.VendedorClientePOPK">
<key-property
name="codVendedor"
column="COD_VENDEDOR"
type="java.lang.String"
length="6"
/>
<key-property
name="codCliente"
column="COD_CLIENTE"
type="java.lang.String"
length="14"
/>
</composite-id>

</class>
</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():
VendedorClientePOPK vendedorClientePK = new VendedorClientePOPK();
VendedorClientePO vendedorCliente = new VendedorClientePO();

vendedorClientePK.setCodCliente( '11111111000299' );
vendedorClientePK.setCodVendedor('222');

session.load(vendedorCliente,vendedorClientePK);

Full stack trace of any exception that occurs:
net.sf.hibernate.ObjectNotFoundException: No row with the given identifier exists: com.probel.fatura.data.VendedorClientePOPK@855379[codVendedor=222,codCliente=11111111000299], of class: com.probel.fatura.data.VendedorClientePO

--> but the row exists.

Name and version of the database you are using:
Oracle 9i

The generated SQL (show_sql=true):
select vendedorcl0_.COD_VENDEDOR as COD_VEND1_0_, vendedorcl0_.COD_CLIENTE as COD_CLIE2_0_ from vendas.VENDEDOR_CLIENTE vendedorcl0_ where vendedorcl0_.COD_VENDEDOR=? and vendedorcl0_.COD_CLIENTE=?

I replace "?" by correct values, execute it in the SQL Plus and it works.

//Table columns:
COD_VENDEDOR char(6)
COD_CLIENTE char(14)

//PK Class
public class VendedorClientePOPK implements Serializable {
private String codVendedor;
private String codCliente;

...

public boolean equals(Object other) {
if ( !(other instanceof VendedorClientePOPK) ) return false;
VendedorClientePOPK castOther = (VendedorClientePOPK) other;
return new EqualsBuilder()
.append(this.getCodVendedor(), castOther.getCodVendedor())
.append(this.getCodCliente(), castOther.getCodCliente())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getCodVendedor())
.append(getCodCliente())
.toHashCode();
}
}

//Persistence Class
public class VendedorClientePO implements Serializable {
private VendedorClientePOPK comp_id;

...

public boolean equals(Object other) {
if ( !(other instanceof VendedorClientePO) ) return false;
VendedorClientePO castOther = (VendedorClientePO) other;
return new EqualsBuilder()
.append(this.getComp_id(), castOther.getComp_id())
.isEquals();
}

public int hashCode() {
return new HashCodeBuilder()
.append(getComp_id())
.toHashCode();
}
}

If anybody can me help, I'm grateful.....

_________________
Adriano Alves Dornelas


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.