• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to implement composite primary key in BMP

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all,
iam using oracle database which has a tables where we can find a single record using three primary key fields,so iwould like to know how to implement this in bmp,
i have written a class accounPk - which has three variables,
help is appreciated.
san
 
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I�ve never done with a triple pk but I�ve done with a double one, also I�m using WL6.1 and ejb20, here goes an example, I think it�ll help you.
regards.
<code>
package br.com.mmaia.ejb20.assucena;
public class MedidorPK implements java.io.Serializable
{
public String nome_empresa;
public String numero_medidor;
private int hashCode = -1;
public MedidorPK() {}
public MedidorPK(String nome_empresa, String numero_medidor)
{
this.nome_empresa = nome_empresa;
this.numero_medidor = numero_medidor;
}
public boolean equals(Object objeto_comparado)
{
if (objeto_comparado == this) return true;
if (!(objeto_comparado instanceof MedidorPK))
return false;

MedidorPK medidorPK = (MedidorPK)objeto_comparado;
if (medidorPK.hashCode() == hashCode()) {
return nome_empresa.equals(medidorPK.nome_empresa) &&
numero_medidor.equals(medidorPK.numero_medidor);
} else {
return false;
}
}

public int hashCode() {
if (hashCode == -1) {
hashCode = nome_empresa.hashCode() ^ numero_medidor.hashCode();
}
return hashCode;
}
public String toString() {
return "(" + nome_empresa + ", " + numero_medidor + ")";
}
}
</code>
 
I would challenge you to a battle of wits, but I see you are unarmed - shakespear. Unarmed tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic