[Resolvido] Erro ao persistir Entidade: Transient Instace

1 resposta
java
M

Bom dia Galera do GUJ.
Estou com um problema no meu sistema e não estou conseguindo resolver de jeito nenhum.

O meu sistema é de vendas, onde tenho as seguintes entidades:
* Item (Produto / Serviço)
* ItemPedido
* Usuario
* Cliente
* Fornecedor
* Pedido

Quando vou persistir um pedido o Hibernate lança uma exceção:

org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : unigranrio.tcc.projetovendas.model.ItemPedido.item -> unigranrio.tcc.projetovendas.model.Item

O mais estranho é que todas as entidades já foram persistidas no banco, e a rotina de gravação do pedido é como se fosse um agregador destas entidades, ou seja, eu leio todas do banco as gravo na entidade Pedido. A minha suspeita é que o meu mapeamento pode estar errado, porém em inúmeras tentativas, não consegui chegar a uma forma que funcione.

Abaixo vou postar o código da classe Pedido, ItemPedido e CadastroPedidoMB.
Desculpe qq coisa, pois sou novo aqui no grupo.

@Entity
@Table(name = ItemPedido.TABLE_NAME)
public class ItemPedido implements Serializable, EntityIdSequencial {

	private static final long serialVersionUID = -173678112041362815L;
	private static final String TABLE_PREFIX   = "item_";
	protected static final String TABLE_NAME   = "tb_item_pedido";

	private Long id;
	private Integer quantidade = 1;
	private BigDecimal valorUnitario = BigDecimal.ZERO;
	private Item item;
	private Pedido pedido;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = TABLE_PREFIX + "id")
	public Long getId() {
		return id;
	}

	@Column(name = TABLE_PREFIX + "quantidade", nullable = false, length = 3)
	public Integer getQuantidade() {
		return quantidade;
	}

	@Column(name = TABLE_PREFIX + "valor_unitario", nullable = false, precision = 10, scale = 2)
	public BigDecimal getValorUnitario() {
		return valorUnitario;
	}

	@ManyToOne
	@JoinColumn(name = TABLE_PREFIX + "item_id", nullable = false)
	public Item getItem() {
		return item;
	}

	@ManyToOne
	@JoinColumn(name = TABLE_PREFIX + "pedido_id", nullable = false)
	public Pedido getPedido() {
		return pedido;
	}

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

	public void setQuantidade(Integer quantidade) {
		this.quantidade = quantidade;
	}

	public void setValorUnitario(BigDecimal valorUnitario) {
		this.valorUnitario = valorUnitario;
	}

	public void setItem(Item item) {
		this.item = item;
	}

	public void setPedido(Pedido pedido) {
		this.pedido = pedido;
	}
}
@Entity
@Table(name = Pedido.TABLE_NAME)
public class Pedido implements EntityIdSequencial, Serializable {

	private static final long serialVersionUID  = 4642284804571389335L;
	private static final String TABLE_PREFIX    = "ped_";
	protected static final String TABLE_NAME    = "tb_pedido";

	private Long id;
	private Date dataCriacao;
	private Date dataEntrega;
	private String observacao;
	private BigDecimal valorFrete = BigDecimal.ZERO;
	private BigDecimal valorDesconto = BigDecimal.ZERO;
	private BigDecimal valorTotal = BigDecimal.ZERO;
	private StatusPedido status = StatusPedido.ORCAMENTO;
	private FormaPagamento formaPagamento;
	private Usuario vendedor;
	private Cliente cliente;
	private Fornecedor fornecedor;
	private Endereco endereco;
	private List<ItemPedido> itens = new ArrayList<>();

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = TABLE_PREFIX + "id")
	public Long getId() {
		return this.id;
	}

	@NotNull
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = TABLE_PREFIX + "data_criacao", nullable = false)
	public Date getDataCriacao() {
		return dataCriacao;
	}

	@NotNull
	@Temporal(TemporalType.DATE)
	@Column(name = TABLE_PREFIX + "data_entrega", nullable = false)
	public Date getDataEntrega() {
		return dataEntrega;
	}

	@Nullable
	@Column(name = TABLE_PREFIX + "observacao", columnDefinition = "text")
	public String getObservacao() {
		return observacao;
	}

	@NotNull
	@Column(name = TABLE_PREFIX + "valor_frete", nullable = false, precision = 10, scale = 2)
	public BigDecimal getValorFrete() {
		return valorFrete;
	}

	@NotNull
	@Column(name = TABLE_PREFIX + "valor_desconto", nullable = false, precision = 10, scale = 2)
	public BigDecimal getValorDesconto() {
		return valorDesconto;
	}

	@NotNull
	@Column(name = TABLE_PREFIX + "valor_total", nullable = false, precision = 10, scale = 2)
	public BigDecimal getValorTotal() {
		return valorTotal;
	}

	@NotNull
	@Enumerated(EnumType.STRING)
	@Column(name = TABLE_PREFIX + "status_pedido", nullable = false, length = 20)
	public StatusPedido getStatus() {
		return status;
	}

	@NotNull
	@Enumerated(EnumType.STRING)
	@Column(name = TABLE_PREFIX + "forma_pagamento", nullable = false, length = 22)
	public FormaPagamento getFormaPagamento() {
		return formaPagamento;
	}

	@NotNull
	@ManyToOne
	@JoinColumn(name = TABLE_PREFIX + "vendedor_id", nullable = false)
	public Usuario getVendedor() {
		return vendedor;
	}

	@NotNull
	@ManyToOne
	@JoinColumn(name = TABLE_PREFIX + "cliente_id", nullable = false)
	public Cliente getCliente() {
		return cliente;
	}

	@NotNull
	@ManyToOne
	@JoinColumn(name = TABLE_PREFIX + "fornecedor_id", nullable = false)
	public Fornecedor getFornecedor() {
		return fornecedor;
	}

	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = TABLE_PREFIX + "endereco_id", nullable = false)
	public Endereco getEndereco() {
		return endereco;
	}

	@NotNull
	@OneToMany(mappedBy = "pedido", cascade = CascadeType.ALL, orphanRemoval = true)
	public List<ItemPedido> getItens() {
		return itens;
	}

	//Setters, hashcode e equals omitidos
	public void adicionarItemVazio() {
		if (this.isOrcamento()) {
			Item produto = new Item();
			ItemPedido item = new ItemPedido();
			
			item.setItem(produto);
			item.setPedido(this);

			this.getItens().add(0, item);
		}
	}

	@Transient
	public boolean isOrcamento() {
		return StatusPedido.ORCAMENTO.equals(this.getStatus());
	}

	@Transient
	public void removerItemVazio() {
		ItemPedido primeiroItem = this.getItens().get(0);

		if (primeiroItem != null && primeiroItem.getItem().getId() == null) {
			this.getItens().remove(0);
		}
	}
}
@Named
@ViewScoped
public class CadastroPedidoMB implements Serializable {

	private static final long serialVersionUID = -3112451104933325313L;

	@Inject
	private Usuarios usuarios;

	@Inject
	private Fornecedores fornecedores;

	@Inject
	private Clientes clientes;

	@Inject
	private Itens produtos;

	// ============[ Classes Services ]=====================

	@Inject
	private CadastroPedidoService cadastroPedidoService;

	@Inject
	private LocalService localService;

	@Produces
	@PedidoEdicao
	private Pedido pedido;

	private Cliente clienteSelecionado;
	private Item produtoLinhaEditavel;

	private String sku = null;
	private Boolean usaEnderecoCliente = false;

	private List<Fornecedor> listaFornecedores = new ArrayList<>();
	private List<Usuario> vendedores = new ArrayList<>();
	private Endereco endereco = new Endereco();

	// Construtor
	public CadastroPedidoMB() {
		limpar();
	}

	public void inicializar() {

		if (JSFUtil.isNotPostback()) {
			this.vendedores = this.usuarios.vendedores();

			this.pedido.adicionarItemVazio();
			this.listaFornecedores = fornecedores.lerTodos();
			this.recalcularPedido();
		}
	}

	private void limpar() {
		pedido = new Pedido();
	}

	public void buscarPorCep() {
		this.endereco = localService.buscaPorCep(endereco.getCep());
	}

	public Date dataMinEntrega() {
		return new Date();
	}

	public void pedidoAlterado(@Observes PedidoAlteradoEvent event) {
		this.pedido = event.getPedido();
	}

	public void salvar() {

		this.pedido.setEndereco(this.endereco);
		this.pedido.setCliente(this.clienteSelecionado);

		this.pedido = this.cadastroPedidoService.salvar(this.pedido);
	}

	public void recalcularPedido() {
		if (this.pedido != null) {
			this.pedido.recalcularValorTotal();
		}
	}

	public void carregarItemPorSku() {
		if (StringUtils.isNotEmpty(this.sku)) {
			this.produtoLinhaEditavel = this.produtos.lerPorSKU(this.sku.toUpperCase());
			this.carregarItemLinhaEditavel();
		}
	}

	public void carregarItemLinhaEditavel() {
		// Pegou primeira linha do data_table
		ItemPedido item = this.pedido.getItens().get(0);

		if (this.produtoLinhaEditavel != null) {
			if (this.existeItemComItem(this.produtoLinhaEditavel)) {
				JSFUtil.retornarMensagemErro("Erro na operação", "Já existe um item no pedido com o produto informado.",
						null);

			} else {
				item.setItem(produtoLinhaEditavel);
				item.setValorUnitario(produtoLinhaEditavel.getValorUnitario());

				this.pedido.adicionarItemVazio();
				this.pedido.recalcularValorTotal();
			}

			this.produtoLinhaEditavel = null;
			this.sku = null;
		}
	}

	private boolean existeItemComItem(Item produto) {
		boolean existeItem = false;

		for (ItemPedido item : this.getPedido().getItens()) {
			if (produto.equals(item.getItem())) {
				existeItem = true;
				break;
			}
		}

		return existeItem;
	}

	public List<Item> completarItem(String nome) {
		return this.produtos.lerPorNome(nome);
	}

	public void atualizarQuantidade(ItemPedido item, int linha) {
		if (item.getQuantidade() < 1) {
			if (linha == 0) {
				item.setQuantidade(1);
			} else {
				this.getPedido().getItens().remove(linha);
			}
		}

		this.pedido.recalcularValorTotal();
	}

	public List<Cliente> completarCliente(String nome) {
		return this.clientes.lerPorNome(nome);
	}

	public Pedido getPedido() {
		return pedido;
	}

	public void setPedido(Pedido pedido) {
		this.pedido = pedido;
	}

	public List<Usuario> getVendedores() {
		return vendedores;
	}

	public boolean isEditando() {
		return this.pedido.getId() != null;
	}

	public Item getItemLinhaEditavel() {
		return produtoLinhaEditavel;
	}

	public void setItemLinhaEditavel(Item produtoLinhaEditavel) {
		this.produtoLinhaEditavel = produtoLinhaEditavel;
	}

	public void preencheEnderecoCliente() {
		if (this.usaEnderecoCliente) {
			if (this.clienteSelecionado != null && this.clienteSelecionado.getId() != null) {
				this.endereco = this.clienteSelecionado.getEndereco();
			} else {
				this.usaEnderecoCliente = false;
				throw new NegocioException("Selecione um cliente.");
			}
		} else {
			this.endereco = new Endereco();
		}
	}

	@SKU
	public String getSku() {
		return sku;
	}

	public void setSku(String sku) {
		this.sku = sku;
	}

	public Item getProdutoLinhaEditavel() {
		return produtoLinhaEditavel;
	}

	public void setProdutoLinhaEditavel(Item produtoLinhaEditavel) {
		this.produtoLinhaEditavel = produtoLinhaEditavel;
	}

	public List<Fornecedor> getListaFornecedores() {
		return listaFornecedores;
	}

	public Endereco getEndereco() {
		return endereco;
	}

	public void setEndereco(Endereco endereco) {
		this.endereco = endereco;
	}

	public Boolean getUsaEnderecoCliente() {
		return usaEnderecoCliente;
	}

	public void setUsaEnderecoCliente(Boolean usaEnderecoCliente) {
		this.usaEnderecoCliente = usaEnderecoCliente;
	}

	public Cliente getClienteSelecionado() {
		return clienteSelecionado;
	}

	public void setClienteSelecionado(Cliente clienteSelecionado) {
		this.clienteSelecionado = clienteSelecionado;
	}
}
2016-05-30 11:06:52,122 ERROR [unigranrio.tcc.projetovendas.util.jsf.JsfExceptionHandler] Erro do Sistema: #{cadastroPedidoMB.salvar}: javax.persistence.RollbackException: Error while committing the transaction
javax.faces.FacesException: #{cadastroPedidoMB.salvar}: javax.persistence.RollbackException: Error while committing the transaction
	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:89)
	at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
	at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:198)
	at javax.faces.webapp.FacesServlet.service(FacesServlet.java:658)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
	at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:54)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilter(BasicAuthenticationFilter.java:150)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:91)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:183)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:105)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
	at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
	at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
	at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
	at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:237)
	at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:522)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
	at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:1096)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:760)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1480)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: javax.faces.FacesException: #{cadastroPedidoMB.salvar}: javax.persistence.RollbackException: Error while committing the transaction
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
	at javax.faces.component.UICommand.broadcast(UICommand.java:315)
	at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:790)
	at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1282)
	at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
	... 54 more
Caused by: javax.faces.el.EvaluationException: javax.persistence.RollbackException: Error while committing the transaction
	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:101)
	at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
	... 58 more
Caused by: javax.persistence.RollbackException: Error while committing the transaction
	at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:86)
	at unigranrio.tcc.projetovendas.util.jpa.TransactionInterceptor.invoke(TransactionInterceptor.java:48)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:30)
	at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:69)
	at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:112)
	at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:88)
	at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:55)
	at unigranrio.tcc.projetovendas.service.CadastroPedidoService$Proxy$_$$_WeldSubclass.salvar(CadastroPedidoService$Proxy$_$$_WeldSubclass.java)
	at unigranrio.tcc.projetovendas.controller.CadastroPedidoMB.salvar(CadastroPedidoMB.java:113)
	at unigranrio.tcc.projetovendas.controller.CadastroPedidoMB$Proxy$_$$_WeldClientProxy.salvar(CadastroPedidoMB$Proxy$_$$_WeldClientProxy.java)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.apache.el.parser.AstValue.invoke(AstValue.java:247)
	at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:267)
	at org.jboss.weld.util.el.ForwardingMethodExpression.invoke(ForwardingMethodExpression.java:39)
	at org.jboss.weld.el.WeldMethodExpression.invoke(WeldMethodExpression.java:50)
	at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
	at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:87)
	... 59 more
Caused by: java.lang.IllegalStateException: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : unigranrio.tcc.projetovendas.model.ItemPedido.item -> unigranrio.tcc.projetovendas.model.Item
	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1689)
	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1608)
	at org.hibernate.jpa.internal.EntityManagerImpl$CallbackExceptionMapperImpl.mapManagedFlushFailure(EntityManagerImpl.java:235)
	at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3139)
	at org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2352)
	at org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:147)
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:231)
	at org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
	at org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
	... 82 more
Caused by: org.hibernate.TransientPropertyValueException: object references an unsaved transient instance - save the transient instance before flushing : unigranrio.tcc.projetovendas.model.ItemPedido.item -> unigranrio.tcc.projetovendas.model.Item
	at org.hibernate.engine.spi.CascadingActions$8.noCascade(CascadingActions.java:379)
	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:119)
	at org.hibernate.event.internal.AbstractSaveEventListener.cascadeBeforeSave(AbstractSaveEventListener.java:414)
	at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:252)
	at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
	at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:125)
	at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
	at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
	at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
	at org.hibernate.internal.SessionImpl.firePersistOnFlush(SessionImpl.java:805)
	at org.hibernate.internal.SessionImpl.persistOnFlush(SessionImpl.java:798)
	at org.hibernate.engine.spi.CascadingActions$8.cascade(CascadingActions.java:340)
	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:391)
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:316)
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:155)
	at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:424)
	at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:356)
	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:319)
	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:155)
	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:104)
	at org.hibernate.event.internal.AbstractFlushingEventListener.cascadeOnFlush(AbstractFlushingEventListener.java:150)
	at org.hibernate.event.internal.AbstractFlushingEventListener.prepareEntityFlushes(AbstractFlushingEventListener.java:141)
	at org.hibernate.event.internal.AbstractFlushingEventListener.flushEverythingToExecutions(AbstractFlushingEventListener.java:74)
	at org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:38)
	at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1295)
	at org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:468)
	at org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:3135)
	... 89 more

1 Resposta

M

Boa noite galera.

Consegui resolver o problema. Era uma validação feita antes do pedido ser salvo que estava sendo executada em um local errado.

abraSOUL!

Criado 30 de maio de 2016
Ultima resposta 30 de mai. de 2016
Respostas 1
Participantes 1