Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to implement composite primary key in BMP  RSS feed

 
ravi bask
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • 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
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • 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>
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!