Hibernate + JSON - Não quero utilizar DTO/VO/

0 respostas
gveloso

Necessidade: Eu só quero carregar uma combo com os setores.

Problema: Mas quando o JSON vai transformar o meu objeto (Setor) Java em JSON ele chama o método getTiposDeProdutoConfigurado() e trás os objetos TipoDeProdutoConfigurado e suas dependências também.

O que eu preciso é que essa coleção de TipoDeProdutoConfigurado não seja carregada nesse momento.

Alguém já viveu uma situação parecida?

package br.com.ewise.brama.bean.common;


import java.util.List;
import java.util.Set;
import java.util.TreeSet;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;


import br.com.ewise.brama.bean.estoque.TipoDeProduto;
import br.com.ewise.brama.bean.estoque.TipoDeProdutoConfigurado;

@Entity
@Table(name="tb_cmm_setor", schema="brama")
public class Setor {
	@Id 
	@SequenceGenerator(name="seq_cmm_setor_id", sequenceName="seq_cmm_setor_id")
	@GeneratedValue(strategy=GenerationType.SEQUENCE, generator="seq_cmm_setor_id")
	@Column(name="nu_id")
	private Integer id;
	
	@Column(name="st_nome", nullable=false, unique=true)
	private String nome;
	 
	@Column(name="bo_ativo", nullable=false)
	private Boolean ativo;
	 
	@OneToMany(mappedBy="setor", fetch=FetchType.LAZY)
	private List<TipoDeProdutoConfigurado> tiposDeProdutoConfigurado;

	public final Integer getId() {
		return id;
	}

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

	public final String getNome() {
		return nome;
	}

	public final void setNome(String nome) {
		this.nome = nome;
	}

	public final Boolean getAtivo() {
		return ativo;
	}

	public final void setAtivo(Boolean ativo) {
		this.ativo = ativo;
	}

	public final List<TipoDeProdutoConfigurado> getTiposDeProdutoConfigurado() {
		return tiposDeProdutoConfigurado;
	}

	public final void setTiposDeProdutoConfigurado(
			List<TipoDeProdutoConfigurado> tiposDeProdutoConfigurado) {
		this.tiposDeProdutoConfigurado = tiposDeProdutoConfigurado;
	}
	
	public String toString(){
		return this.nome;		
	}

	public Set<TipoDeProduto> getTiposDeProdutoTronco() {

		//TODO: The list has to be returned in ordering.
		Set<TipoDeProduto> tiposDeProdutoTronco = new TreeSet<TipoDeProduto>();
		
		for (TipoDeProdutoConfigurado tipoDeProdutoConfigurado : this.tiposDeProdutoConfigurado) {
			tiposDeProdutoTronco.add(tipoDeProdutoConfigurado.getTipoDeProdutoTronco());
		}
		
		return tiposDeProdutoTronco;
	}
	
}
Criado 27 de abril de 2009
Respostas 0
Participantes 1