Hi all,
I have one table in postgresql with four primary keys. I want to know how to do a select with this four keys. My code is like this:
tTickets.hbm.xml
Code:
<hibernate-mapping package="bbdd.modelos">
<class name="tTickets"
table="tickets" lazy="true">
<composite-id>
<key-property name="Tienda" column="tienda" type="string"/>
<key-property name="Num_Ticket" column="num_ticket" type="string"/>
<key-property name="TPV" column="tpv" type="string"/>
<key-property name="Fecha" column="fecha" type="date"/>
</composite-id>
<property name="Ticket"
type="string"
column="ticket"
not-null="true"/>
</class>
</hibernate-mapping>
tTickets.javaCode:
package bbdd.modelos;
import java.util.Date;
import java.io.Serializable;
/**
*
* @author Administrador
*/
public class tTickets implements Serializable {
private String sTienda;
private String sNum_Ticket;
private String sTPV;
private Date dFecha;
private String sTicket;
/** Creates a new instance of tTickets */
tTickets() { }
public tTickets(String sTienda, String sNum_Ticket, String sTPV, Date dFecha, String sTicket) {
this.sTienda = sTienda;
this.sNum_Ticket = sNum_Ticket;
this.sTPV = sTPV;
this.dFecha = dFecha;
this.sTicket = sTicket;
}
public String getTienda() { return sTienda; }
public String getNum_Ticket() { return sNum_Ticket; }
public String getTPV() { return sTPV; }
public Date getFecha() { return dFecha; }
public String getTicket() { return sTicket; }
public void setTienda(String sTienda) { this.sTienda = sTienda; }
public void setNum_Ticket(String sNum_Ticket) { this.sNum_Ticket = sNum_Ticket; }
public void setTPV(String sTPV) { this.sTPV = sTPV; }
public void setFecha(Date dFecha) { this.dFecha = dFecha; }
public void setTicket(String sTicket) { this.sTicket = sTicket; }
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof tTickets)) return false;
final tTickets tickets = (tTickets) o;
if (!sTienda.equals(tickets.sTienda)) return false;
if (!sTPV.equals(tickets.sTPV)) return false;
if (!sNum_Ticket.equals(tickets.sNum_Ticket)) return false;
return true;
}
public int hashCode() {
int result;
result = sTienda.hashCode();
result = 29 * result + sTPV.hashCode();
result = 29 * result + sNum_Ticket.hashCode();
return result;
}
}
TicketsDAO.javaCode:
package bbdd.dao;
import org.hibernate.*;
import exceptions.bbddExceptions;
import bbdd.modelos.tTickets;
import bbdd.oConexion;
import java.io.Serializable;
import java.util.Collection;
public class TicketsDAO {
public TicketsDAO() {
oConexion.beginTransaction();
}
// ********************************************************** //
public tTickets getTicket(tTickets ticket, boolean lock)
throws bbddExceptions {
Session session = oConexion.getSession();
tTickets tickets = null;
try {
if (lock) {
tickets = (tTickets) session.load(tTickets.class, ticket , LockMode.UPGRADE);
} else {
tickets = (tTickets) session.load(tTickets.class, ticket);
}
} catch (HibernateException ex) {
throw new bbddExceptions(ex);
}
return tickets;
}
public Collection findAll()
throws bbddExceptions {
Collection items;
try {
items = oConexion.getSession().createCriteria(tTickets.class).list();
} catch (HibernateException ex) {
throw new bbddExceptions(ex);
}
return items;
}
// ********************************************************** //
public void save(tTickets tickets)
throws bbddExceptions {
try {
oConexion.getSession().saveOrUpdate(tickets);
} catch (HibernateException ex) {
throw new bbddExceptions(ex);
}
}
// ********************************************************** //
public void delete(tTickets tickets)
throws bbddExceptions {
try {
oConexion.getSession().delete(tickets);
} catch (HibernateException ex) {
throw new bbddExceptions(ex);
}
}
}
Is all right? Or there is any problem?. In this code i want that in select you might pass to postgresql four parameters (In one tTicket Object) and make query, but It doesn't work.
Please Help!!!!
Thanks a lot.[/b]