IntelliJ Java IDE
The moose likes EJB and Other Java EE Technologies and the fly likes How to implement composite primary key in BMP Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "How to implement composite primary key in BMP" Watch "How to implement composite primary key in BMP" New topic
Author

How to implement composite primary key in BMP

ravi bask
Ranch Hand

Joined: Jul 05, 2001
Posts: 58
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

Joined: Jan 06, 2001
Posts: 973
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>
 
jQuery in Action, 2nd edition
 
subject: How to implement composite primary key in BMP
 
Threads others viewed
BMP
CMP bean problem with auto generated primary key
Hibernate Mapping problem because no primary key in database
How can we access praimary key in Entity Beans -BMP?
Dealing with composite primary keys
developer file tools