Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

rbrit0

Erro com Toplink

Recommended Posts

EStou desenvolvendo um Web Service REST com o NetBeans, com o plugin da API Jersey.

No entanto começou dar pau no mapeamento das classes no toplink. Já refiz o Web Service várias vezes mas o erro persiste.

Segue o erro:

 

javax.persistence.PersistenceException: Exception [TOPLINK-0] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.IntegrityException

Descriptor Exceptions:

---------------------------------------------------------

 

Exception [TOPLINK-48] (Oracle TopLink Essentials - 2.0.1 (Build b09d-fcs (12/06/2007))): oracle.toplink.essentials.exceptions.DescriptorException

Exception Description: Multiple writable mappings exist for the field [agenda.usuario]. Only one may be defined as writable, all others must be specified read-only.

Mapping: oracle.toplink.essentials.mappings.OneToOneMapping[usuario]

 

E aqui o código do mapeamento:

/*
 * PersistenceService.java
 *
 * Created on 4 de Agosto de 2008, 10:27
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package service;

import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.Query;

/**
 * Utility class for dealing with persistence.
 *
 * @author Rafael
 */
public class PersistenceService {
	private static String DEFAULT_PU = "AgendaWebServicePU";
	
	private static ThreadLocal<PersistenceService> instance = new ThreadLocal<PersistenceService>() {
		protected PersistenceService initialValue() {
			return new PersistenceService(DEFAULT_PU);
		}
	};
	
	private EntityManagerFactory emf;
	private EntityManager em;
	
	private PersistenceService(String puName) {
		try {
			this.emf = Persistence.createEntityManagerFactory(puName);
			this.em = emf.createEntityManager();
		} catch (RuntimeException ex) {
			if (emf != null) {
				emf.close();
			}
			
			throw ex;
		}
	}
	
	/**
	 * Returns an instance of PersistenceService.
	 * 
	 * @return an instance of PersistenceService
	 */
	public static PersistenceService getInstance() {
		return instance.get();
	}
	
	private static void removeInstance() {
		instance.remove();
	}
	
	/**
	 * Refreshes the state of the given entity from the database.
	 * 
	 * @param entity the entity to refresh
	 */
	public void refreshEntity(Object entity) {
		em.refresh(entity);
	}
	
	/**
	 * Merges the state of the given entity into the current persistence context.
	 * 
	 * @param entity the entity to merge
	 * @return the merged entity
	 */
	public <T> T mergeEntity(T entity) {
		return (T) em.merge(entity);
	}
	
	/**
	 * Makes the given entity managed and persistent.
	 * 
	 * @param entity the entity to persist
	 */
	public void persistEntity(Object entity) {
		em.persist(entity);
	}
	
	/**
	 * Removes the entity instance.
	 * 
	 * @param entity the entity to remove
	 */
	public void removeEntity(Object entity) {
		em.remove(entity);
	}
	
	/**
	 * Resolves the given entity to the actual entity instance in the current persistence context.
	 *
	 * @param entity the entity to resolve
	 * @return the resolved entity
	 */
	public <T> T resolveEntity(T entity) {
		entity = mergeEntity(entity);
		em.refresh(entity);
		
		return entity;
	}
	
	/**
	 * Returns an instance of Query for executing a named query.
	 * 
	 * @param query the named query
	 * @return an instance of Query
	 */
	public Query createNamedQuery(String query) {
		return em.createNamedQuery(query);
	}
	
	/**
	 * Returns an instance of Query for executing a query.
	 * 
	 * @param query the query string
	 * @return an instance of Query
	 */
	public Query createQuery(String query) {
		return em.createQuery(query);
	}
	
	/**
	 * Begins a resource transaction.
	 */
	public void beginTx() {
		EntityTransaction tx = em.getTransaction();

		if (!tx.isActive()) {
			tx.begin();
		}
	}
	
	/**
	 * Commits a resource transaction.
	 */
	public void commitTx() {
		EntityTransaction tx = em.getTransaction();
		
		if (tx.isActive()) {
			tx.commit();
		}
	}
	
	/**
	 * Rolls back a resource transaction.
	 */
	public void rollbackTx() {
		EntityTransaction tx = em.getTransaction();
		
		if (tx.isActive()) {
			tx.rollback();
		}
	}
	
	/**
	 * Closes this instance.
	 */
	public void close() {
		if (em != null && em.isOpen()) {
			rollbackTx();
			em.close();
		}
		
		if (emf != null && emf.isOpen()) {
			emf.close();
		}
		
		removeInstance();
	}
}

Compartilhar este post


Link para o post
Compartilhar em outros sites

Da uma olhada neste erro, ja está praticamente dizendo tudo.

 

Exception Description: Multiple writable mappings exist for the field [agenda.usuario]. Only one may be defined as writable, all others must be specified read-only.

 

Flwww, grande abraço

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.