Pessoal , boa noite ,
Estou fazendo um projeto próprio terminei a modelagem do banco e ficou com 42 tabelas ( nada muito grande,mas vai ser um sistema web ) , após pesquisar na internet vi que o hibernate tools poderia gerar tanto as classes básicas já com annotations e o DAO tb…
Consegui fazer e achei o código bastante limpo , não tenho muita experiência com hibernate (mais jdbc).
Gostaria de saber se tal classes geradas prejudicariam a performance ( achei muito grande a quantidade de jars necessários ) , e como não tive muito contato com hibernate e muito menos com classes geradas automaticamente , fiquei com essa “pulga atrás da orelha”!!!
segue abaixo um exemplo da classe cliente gerada (foi gerada testando o hibernate tools apartir do banco postgre e sem nenhum relacionamento com outra tabela).
Só pra ajudar a galera : na modelagem do banco eu usei o dbdesigner fork (é uma versão que você pode exportar o script do banco p/ vários bancos diferentes)…
package demo;
// Generated 29/03/2011 23:31:55 by Hibernate Tools 3.4.0.CR1
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
/**
* Cliente generated by hbm2java
*/
@Entity
@Table(name = "cliente")
public class Cliente implements java.io.Serializable {
private int idCliente;
private String nmCliente;
private String dsTel;
private String dsCel;
private String dsEmail;
private String snAtivo;
private String dsAnotacao;
private String dsBkp;
private Double cdBkp;
private Date dtCadastro;
public Cliente() {
}
public Cliente(int idCliente, String nmCliente, Date dtCadastro) {
this.idCliente = idCliente;
this.nmCliente = nmCliente;
this.dtCadastro = dtCadastro;
}
public Cliente(int idCliente, String nmCliente, String dsTel, String dsCel,
String dsEmail, String snAtivo, String dsAnotacao, String dsBkp,
Double cdBkp, Date dtCadastro) {
this.idCliente = idCliente;
this.nmCliente = nmCliente;
this.dsTel = dsTel;
this.dsCel = dsCel;
this.dsEmail = dsEmail;
this.snAtivo = snAtivo;
this.dsAnotacao = dsAnotacao;
this.dsBkp = dsBkp;
this.cdBkp = cdBkp;
this.dtCadastro = dtCadastro;
}
@Id
@Column(name = "id_cliente", unique = true, nullable = false)
public int getIdCliente() {
return this.idCliente;
}
public void setIdCliente(int idCliente) {
this.idCliente = idCliente;
}
@Column(name = "nm_cliente", nullable = false, length = 45)
public String getNmCliente() {
return this.nmCliente;
}
public void setNmCliente(String nmCliente) {
this.nmCliente = nmCliente;
}
@Column(name = "ds_tel", length = 45)
public String getDsTel() {
return this.dsTel;
}
public void setDsTel(String dsTel) {
this.dsTel = dsTel;
}
@Column(name = "ds_cel", length = 45)
public String getDsCel() {
return this.dsCel;
}
public void setDsCel(String dsCel) {
this.dsCel = dsCel;
}
@Column(name = "ds_email", length = 45)
public String getDsEmail() {
return this.dsEmail;
}
public void setDsEmail(String dsEmail) {
this.dsEmail = dsEmail;
}
@Column(name = "sn_ativo", length = 2)
public String getSnAtivo() {
return this.snAtivo;
}
public void setSnAtivo(String snAtivo) {
this.snAtivo = snAtivo;
}
@Column(name = "ds_anotacao")
public String getDsAnotacao() {
return this.dsAnotacao;
}
public void setDsAnotacao(String dsAnotacao) {
this.dsAnotacao = dsAnotacao;
}
@Column(name = "ds_bkp")
public String getDsBkp() {
return this.dsBkp;
}
public void setDsBkp(String dsBkp) {
this.dsBkp = dsBkp;
}
@Column(name = "cd_bkp", precision = 17, scale = 17)
public Double getCdBkp() {
return this.cdBkp;
}
public void setCdBkp(Double cdBkp) {
this.cdBkp = cdBkp;
}
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "dt_cadastro", nullable = false, length = 29)
public Date getDtCadastro() {
return this.dtCadastro;
}
public void setDtCadastro(Date dtCadastro) {
this.dtCadastro = dtCadastro;
}
}
Dao gerado pelo hibernate tools
package demo;
// Generated 29/03/2011 23:31:55 by Hibernate Tools 3.4.0.CR1
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* Home object for domain model class Cliente.
* @see demo.Cliente
* @author Hibernate Tools
*/
@Stateless
public class ClienteHome {
private static final Log log = LogFactory.getLog(ClienteHome.class);
@PersistenceContext
private EntityManager entityManager;
public void persist(Cliente transientInstance) {
log.debug("persisting Cliente instance");
try {
entityManager.persist(transientInstance);
log.debug("persist successful");
} catch (RuntimeException re) {
log.error("persist failed", re);
throw re;
}
}
public void remove(Cliente persistentInstance) {
log.debug("removing Cliente instance");
try {
entityManager.remove(persistentInstance);
log.debug("remove successful");
} catch (RuntimeException re) {
log.error("remove failed", re);
throw re;
}
}
public Cliente merge(Cliente detachedInstance) {
log.debug("merging Cliente instance");
try {
Cliente result = entityManager.merge(detachedInstance);
log.debug("merge successful");
return result;
} catch (RuntimeException re) {
log.error("merge failed", re);
throw re;
}
}
public Cliente findById(int id) {
log.debug("getting Cliente instance with id: " + id);
try {
Cliente instance = entityManager.find(Cliente.class, id);
log.debug("get successful");
return instance;
} catch (RuntimeException re) {
log.error("get failed", re);
throw re;
}
}
}
vlws!!!