Foros del Web » Programación para mayores de 30 ;) » Java »

Hibernate con postgres.

Estas en el tema de Hibernate con postgres. en el foro de Java en Foros del Web. Tengo la siguiente tabla en postgres: CREATE TABLE abaliarh.sector ( "NOMBRE" character varying(50), "ID" integer NOT NULL DEFAULT nextval('abaliarh."sector_ID_seq"'::regclass) ) WITH ( OIDS=FALSE ); ALTER ...
  #1 (permalink)  
Antiguo 07/10/2009, 12:10
 
Fecha de Ingreso: octubre-2008
Ubicación: Madrid
Mensajes: 352
Antigüedad: 15 años, 7 meses
Puntos: 5
Hibernate con postgres.

Tengo la siguiente tabla en postgres:

CREATE TABLE abaliarh.sector
(
"NOMBRE" character varying(50),
"ID" integer NOT NULL DEFAULT nextval('abaliarh."sector_ID_seq"'::regclass)
)
WITH (
OIDS=FALSE
);
ALTER TABLE abaliarh.sector OWNER TO postgres;

Al hacer ingenieria inversa me ha generado dos clases:

package com.ibtim.proyectoInicial.persistencia.entidades;

// Generated 06-oct-2009 19:36:25 by Hibernate Tools 3.2.5.Beta

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
* Sector generated by hbm2java
*/
@Entity
@Table(name = "sector", schema = "abaliarh")
public class Sector implements java.io.Serializable {

private SectorId id;

public Sector() {
}

public Sector(SectorId id) {
this.id = id;
}

@EmbeddedId
@AttributeOverrides( {
@AttributeOverride(name = "nombre", column = @Column(name = "NOMBRE", length = 50)),
@AttributeOverride(name = "id", column = @Column(name = "ID", nullable = false)) })
public SectorId getId() {
return this.id;
}

public void setId(SectorId id) {
this.id = id;
}

}

y otra embebida:

package com.ibtim.proyectoInicial.persistencia.entidades;

// Generated 06-oct-2009 19:36:25 by Hibernate Tools 3.2.5.Beta

import javax.persistence.Column;
import javax.persistence.Embeddable;

/**
* SectorId generated by hbm2java
*/
@Embeddable
public class SectorId implements java.io.Serializable {

private String nombre;
private int id;

public SectorId() {
}

public SectorId(int id) {
this.id = id;
}

public SectorId(String nombre, int id) {
this.nombre = nombre;
this.id = id;
}

@Column(name = "NOMBRE", length = 50)
public String getNombre() {
return this.nombre;
}

public void setNombre(String nombre) {
this.nombre = nombre;
}

@Column(name = "ID", nullable = false)
public int getId() {
return this.id;
}

public void setId(int id) {
this.id = id;
}

public boolean equals(Object other) {
if ((this == other))
return true;
if ((other == null))
return false;
if (!(other instanceof SectorId))
return false;
SectorId castOther = (SectorId) other;

return ((this.getNombre() == castOther.getNombre()) || (this
.getNombre() != null
&& castOther.getNombre() != null && this.getNombre().equals(
castOther.getNombre())))
&& (this.getId() == castOther.getId());
}

public int hashCode() {
int result = 17;

result = 37 * result
+ (getNombre() == null ? 0 : this.getNombre().hashCode());
result = 37 * result + this.getId();
return result;
}

}


A la hora de hacer un save, yo solo le tengo que dar un nombre, y el en teoria genrar el autonumerico.

¿Como seria la query para hacerlo?

¿Deberia instanciar un objeto SectorId?

meterle un nombre:

--SectorId.setNombre="nombreSector"

y luego en el dao hacer la siguiente implementacion:

--public void save(SectorId sector) {
getSession().save(sector);


}


O como sería...porque no se como hacerlo...gracias.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:50.