Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » em.persist trigger duplicate insertion
em.persist trigger duplicate insertion [message #638162] Wed, 10 November 2010 04:20 Go to next message
Edmondo is currently offline Edmondo
Messages: 11
Registered: October 2010
Junior Member
Good morning everybody,
I am currently using eclipse link 2.0 for helios and I run in this problem.

I have a Curve which has a list of security. Each security has a list of possible source of information.
package gotware.finance.curves;

import gotware.dataobject.messaging.CopiableForTransmission;
import gotware.dataobject.messaging.MessagingInformationHolder;
import gotware.factories.NotifiersFactory;
import gotware.finance.base.Security;
import gotware.finance.currency.Currency;
import gotware.interfaces.Notifier;
import gotware.messaging.MessagingConstants;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;

/**
 * Entity implementation class for Entity: Curve
 *
 */
@Entity
public class Curve implements Serializable, CopiableForTransmission {

	@Id
	private String curveName;
	private String description;
	private static final long serialVersionUID = 1L;
	@ManyToOne(cascade=CascadeType.ALL,fetch=FetchType.EAGER)
	private Currency currency;
	@ManyToMany(mappedBy = "associatedCurves",fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	private List<Security> securityList = new ArrayList<Security>();
	@OneToMany(fetch=FetchType.EAGER,cascade=CascadeType.ALL,mappedBy="curve")
	@OrderBy("time desc")  
	private List<CurvePoint> curvePoints;
	@Transient
	Notifier notifier;
	// Real-time related data
	@Embedded
	MessagingInformationHolder messagingInformationHolder;
	
	
	public Curve(){
		super();
	}
	
	public Curve(List<Security> securityList) {
		super();
		this.securityList=securityList;
	}
	
	@Override
	public Object cloneWithoutReferences() {
		try {
			Curve newCurve = (Curve) this.clone();
			// Removing transient and not serializable fields
			newCurve.setNotifier(null);
			List<Security> securityList= newCurve.getSecurityList();
			for (int i = 0; i < securityList.size(); i++) {
				Security sec = securityList.get(i);
				Security newSec = (Security) sec.cloneWithoutReferences();
				securityList.set(i, newSec);
			}
			return newCurve;
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
	public Currency getCurrency() {
		return currency;
	}
	public String getCurveName() {
		return curveName;
	}
	public List<CurvePoint> getCurvePoints() {
		return curvePoints;
	}
	public String getDescription() {
		return description;
	}

	
	public List<String> getLabels(){
		// TODO This method should be overwritten by special implementation of the curve class to provide the label of the x axis of the curve
		List<String> labels = new ArrayList<String>();
		Iterator<Security> securityIterator = securityList.iterator();
		while (securityIterator.hasNext()) {
			Security security = securityIterator.next();
			labels.add(security.getName());
		}
		return labels;
	}
	public MessagingInformationHolder getMessagingInformationHolder() {
		return messagingInformationHolder;
	}
	public Notifier getNotifier() {
		return notifier;
	}
	public List<Security> getSecurityList() {
		return securityList;
	}
	   
	
	public void initNotifier(){
		if(messagingInformationHolder!=null){
			notifier =  NotifiersFactory.getDefaultNotifier(messagingInformationHolder.getConnectionFactoryName(), messagingInformationHolder.getTopicName());
		}
	}
	public void recomputeNewCurve(){
		// TODO: to be ovverridden in specific curves implementation updating values array
		// This should modify curvePoints array
		Iterator<Security> iterSec = securityList.iterator();
		// TODO : remove this sample code
		for(int i=0;i<securityList.size();i++){
			Security security = securityList.get(i);
			if(curvePoints.size()>i){
				CurvePoint point = curvePoints.get(i);
				point.setValue(security.getMarketData().getLastPrice());
			}
		}
	}
	
	public void setCurrency(Currency currency) {
		this.currency = currency;
	}
	public void setCurveName(String curveName) {
		this.curveName = curveName;
	}
	
	public void setCurvePoints(List<CurvePoint> curvePoints) {
		this.curvePoints = curvePoints;
	}
	
	public void setDescription(String description) {
		this.description = description;
	}
	
	public void setMessagingInformationHolder(
			MessagingInformationHolder messagingInformationHolder) {
		this.messagingInformationHolder = messagingInformationHolder;
		initNotifier();
	}
	public void setNotifier(Notifier notifier) {
		this.notifier = notifier;
	}
	
	public void setSecurityList(List<Security> securityList) {
		this.securityList = securityList;
	}

	public void update(Security security){
		recomputeNewCurve(); 
		Curve notificationCurve = (Curve) this.cloneWithoutReferences();
			notifier.notifyUpdate(MessagingConstants.MESSAGE_TYPE_GOTWARECURVE, notificationCurve);
	}
}




Then I have a Security:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gotware.finance.base;

import gotware.dataobject.messaging.CopiableForTransmission;
import gotware.finance.curves.Curve;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

/**
 * 
 * @author porcu
 */
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public abstract class Security implements Serializable,CopiableForTransmission {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	@Id
	protected String name;

	protected String market;

	protected String description;

	protected int maturity;

	@NotNull
	@OneToMany(mappedBy = "security", fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	@OrderBy("priority desc")
	protected List<Source> sources;

	@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
	protected List<Curve> associatedCurves;
	@Transient
	MarketData marketData = new MarketData();
	@Transient
	protected List<Source> activeSources = new ArrayList<Source>();
	public Security() {
	}
	public Security(String name, String market) {
		this.name = name;
		this.market = market;

	}

	public Security(String name, String market, String ticker) {
		this.name = name;
		this.market = market;

	}

	public Security(String name, String market, String ticker,
			String description) {
		this.name = name;
		this.market = market;

		this.description = description;
	}

	public void addActiveSource(Source source){
		activeSources.add(source);
	}

	@Override
	public Object cloneWithoutReferences() {
		try {
			Security newSec = (Security) this.clone();
			newSec.setAssociatedCurves(null);
			return newSec;
		} catch (CloneNotSupportedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 
		return null;
	}

	public List<Curve> getAssociatedCurves() {
		return associatedCurves;
	}

	public String getDescription() {
		return description;
	}

	public String getMarket() {
		return market;
	}

	public MarketData getMarketData() {
		return marketData;
	}

	public int getMaturity() {
		return maturity;
	}

	public String getName() {
		return name;
	}

	public List<Source> getSources() {
		return sources;
	}

	public Source removeActiveSource(Source source){
		if(!activeSources.remove(source)) {
			return null;
		}
		return source;
	}

	public void setAssociatedCurves(List<Curve> associatedCurves) {
		this.associatedCurves = associatedCurves;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public void setMarket(String market) {
		this.market = market;
	}

	public void setMarketData(MarketData marketData) {
		this.marketData = marketData;
	}

	public void setMaturity(int maturity) {
		this.maturity = maturity;
	}
	
	public void setName(String name) {
		this.name = name;
	}
	
	public void setSources(List<Source> sources) {
		this.sources = sources;
	}

	public void update() {
		Iterator<Curve> curveIterator = associatedCurves.iterator();
		while (curveIterator.hasNext()) {
			Curve curve = curveIterator.next();
			curve.update(this);
			
		}
	}
}


and a class Source
package gotware.finance.base;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

/**
 * Entity implementation class for Entity: Ticker
 *
 */
@Entity

public class Source implements Serializable {
	public enum DataProvider implements Serializable {
		BLOOMBERG,
		REUTERS,
		OTHER
	}
	@Id
	private String tickerName;
	@NotNull
	@Column(unique=true)
	private int priority=0;
	@NotNull
	private DataProvider dataProvider;
	@ManyToOne(fetch=FetchType.EAGER)
	private Security security;
	@Transient
	boolean active=false;



	private static final long serialVersionUID = 1L;

	public Source() {
		super();
	}

	/**
	 * @param tickerName
	 * @param priority
	 * @param dataProvider
	 */
	public Source(String tickerName, int priority, DataProvider dataProvider) {
		super();
		this.tickerName = tickerName;
		this.priority = priority;
		this.dataProvider = dataProvider;
	}

	/**
	 * @param tickerName
	 * @param priority
	 * @param dataProvider
	 * @param security
	 */
	public Source(String tickerName, int priority, DataProvider dataProvider,
			Security security) {
		super();
		this.tickerName = tickerName;
		this.priority = priority;
		this.dataProvider = dataProvider;
		this.security = security;
	}

	public DataProvider getDataProvider() {
		return dataProvider;
	}

	public int getPriority() {
		return priority;
	}
	
	public Security getSecurity() {
		return security;
	}

	public String getTickerName() {
		return tickerName;
	}

	public boolean isActive() {
		return active;
	}

	public void setActive(boolean active) {
		this.active = active;
	}

	public void setDataProvider(DataProvider dataProvider) {
		this.dataProvider = dataProvider;
	}

	public void setPriority(int priority) {
		this.priority = priority;
	}

	public void setSecurity(Security security) {
		this.security = security;
	}

	public void setTickerName(String tickerName) {
		this.tickerName = tickerName;
	}
   
}


When I run the following code:

    private CurvePoint createCurvePoint(int i, Curve curve){
    	CurvePoint curvePoint = new CurvePoint();
    	int index = 1230 + i+1;
    	curvePoint.setGotwareTicker("GOTX"+(i+1));
    	Calendar calendar = new GregorianCalendar(2010,i,1);
    	curvePoint.setTime(calendar.getTime());
    	curvePoint.setCurve(curve);
    	curvePoint.setValue(new BigDecimal(i).divide(BigDecimal.TEN,3,RoundingMode.FLOOR));
    	return curvePoint;
    }
    
    private EoniaSwap createEonia(int i){
    	EoniaSwap eonia1 = new EoniaSwap();
    	eonia1.setDescription("Daily fixing compounded over period stipulated");
    	eonia1.setName("Eonia " + (i+1) + " month swap");
    	String tickerName = "EUSWE" + (i+1) + "Z Curncy";
    	Source source = new Source(tickerName,0,Source.DataProvider.BLOOMBERG,eonia1);
    	List<Source> sources = new ArrayList<Source>();
    	sources.add(source);
    	eonia1.setSources(sources);
    	eonia1.setMaturity(i);
    	BigDecimal bigDecimal1= new BigDecimal(i).divide(BigDecimal.TEN,3,RoundingMode.FLOOR);
     	eonia1.getMarketData().setLastPrice(bigDecimal1);
     	return eonia1;
    }
    public void test(){
    	List<Security> securityList = new ArrayList<Security>();
     	Currency currency = new Currency(GotwareDatabaseConstants.CURRENCY_AREA_EURO);
     	Curve eoniaCurve = new Curve(securityList);
     	MessagingInformationHolder messagingInformationHolder = new MessagingInformationHolder("/GotwareTopic/MarketData","TopicConnectionFactory");
     	eoniaCurve.setMessagingInformationHolder(messagingInformationHolder);
     	List<Curve> curves = new ArrayList<Curve>();
     	curves.add(eoniaCurve);
     	for(int k=0;k<2;k++){
     		EoniaSwap eoniaSwap = createEonia(k);
     		securityList.add(eoniaSwap);
     		eoniaSwap.setAssociatedCurves(new ArrayList<Curve>(curves));
         	//em.persist(eoniaSwap);
     	}     	
     	eoniaCurve.setCurveName("Our first curve");
     	eoniaCurve.setCurrency(currency);
     	List<CurvePoint> curvePoints = new ArrayList<CurvePoint>();
     	for(int k=0;k<8;k++){
     		CurvePoint curvePoint = createCurvePoint(k,eoniaCurve);
     		curvePoints.add(curvePoint);

         	//em.persist(eoniaSwap);
     	}
     	eoniaCurve.setCurvePoints(curvePoints);
     	currency.setCurves(curves);
     	//em.persist(eoniaCurve);
     	
     	em.persist(currency);
     	//em.flush();

    }

I get this error:

PLUS FIN: TX beforeCompletion callback, status=STATUS_ACTIVE
PLUS FIN: begin unit of work commit
PLUS FIN: TX beginTransaction, status=STATUS_ACTIVE
LE PLUS FIN: Execute query InsertObjectQuery(gotware.finance.ois.EoniaSwap@301d54bf)
LE PLUS FIN: reconnecting to external connection pool
FIN: INSERT IGNORE INTO SECURITY (NAME, MARKET, MATURITY, DESCRIPTION, DTYPE) VALUES (?, ?, ?, ?, ?)
	bind => [Eonia 2 month swap, null, 1, Daily fixing compounded over period stipulated, EoniaSwap]
LE PLUS FIN: Execute query InsertObjectQuery(gotware.finance.ois.EoniaSwap@2192bcac)
FIN: INSERT IGNORE INTO SECURITY (NAME, MARKET, MATURITY, DESCRIPTION, DTYPE) VALUES (?, ?, ?, ?, ?)
	bind => [Eonia 1 month swap, null, 0, Daily fixing compounded over period stipulated, EoniaSwap]
LE PLUS FIN: Execute query InsertObjectQuery(gotware.finance.base.Source@55a6e046)
LE PLUS FIN: Execute query WriteObjectQuery(gotware.finance.ois.EoniaSwap@301d54bf)
FIN: INSERT IGNORE INTO SOURCE (TICKERNAME, DATAPROVIDER, PRIORITY, SECURITY_NAME) VALUES (?, ?, ?, ?)
	bind => [EUSWE2Z Curncy, 0, 0, Eonia 2 month swap]
LE PLUS FIN: Execute query InsertObjectQuery(gotware.finance.base.Source@72afc3e8)
LE PLUS FIN: Execute query WriteObjectQuery(gotware.finance.ois.EoniaSwap@2192bcac)
FIN: INSERT IGNORE INTO SOURCE (TICKERNAME, DATAPROVIDER, PRIORITY, SECURITY_NAME) VALUES (?, ?, ?, ?)
	bind => [EUSWE1Z Curncy, 0, 0, Eonia 1 month swap]
FIN: VALUES(1)
ATTENTION: Local Exception Stack: 
Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.0.1.v20100213-r6600): org.eclipse.persistence.exceptions.DatabaseException
Internal Exception: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL101109154551780' defined on 'SOURCE'.
Error Code: -1
Call: INSERT IGNORE INTO SOURCE (TICKERNAME, DATAPROVIDER, PRIORITY, SECURITY_NAME) VALUES (?, ?, ?, ?)
	bind => [EUSWE1Z Curncy, 0, 0, Eonia 1 month swap]
Query: InsertObjectQuery(gotware.finance.base.Source@72afc3e8)
at org.eclipse.persistence.exceptions.DatabaseException.sqlException(DatabaseException.java:324)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:801)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeNoSelect(DatabaseAccessor.java:867)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:587)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:530)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeCall(AbstractSession.java:914)
	at org.eclipse.persistence.internal.sessions.IsolatedClientSession.executeCall(IsolatedClientSession.java:131)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:205)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.executeCall(DatasourceCallQueryMechanism.java:191)
	at org.eclipse.persistence.internal.queries.DatasourceCallQueryMechanism.insertObject(DatasourceCallQueryMechanism.java:334)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:162)
	at org.eclipse.persistence.internal.queries.StatementQueryMechanism.insertObject(StatementQueryMechanism.java:177)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.insertObjectForWrite(DatabaseQueryMechanism.java:461)
	at org.eclipse.persistence.queries.InsertObjectQuery.executeCommit(InsertObjectQuery.java:80)
	at org.eclipse.persistence.queries.InsertObjectQuery.executeCommitWithChangeSet(InsertObjectQuery.java:90)
	at org.eclipse.persistence.internal.queries.DatabaseQueryMechanism.executeWriteWithChangeSet(DatabaseQueryMechanism.java:286)
	at org.eclipse.persistence.queries.WriteObjectQuery.executeDatabaseQuery(WriteObjectQuery.java:58)
	at org.eclipse.persistence.queries.DatabaseQuery.execute(DatabaseQuery.java:675)
	at org.eclipse.persistence.queries.DatabaseQuery.executeInUnitOfWork(DatabaseQuery.java:589)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWorkObjectLevelModifyQuery(ObjectLevelModifyQuery.java:109)
	at org.eclipse.persistence.queries.ObjectLevelModifyQuery.executeInUnitOfWork(ObjectLevelModifyQuery.java:86)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.internalExecuteQuery(UnitOfWorkImpl.java:2857)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1225)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1207)
	at org.eclipse.persistence.internal.sessions.AbstractSession.executeQuery(AbstractSession.java:1167)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitNewObjectsForClassWithChangeSet(CommitManager.java:197)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsForClassWithChangeSet(CommitManager.java:164)
	at org.eclipse.persistence.internal.sessions.CommitManager.commitAllObjectsWithChangeSet(CommitManager.java:116)
	at org.eclipse.persistence.internal.sessions.AbstractSession.writeAllObjectsWithChangeSet(AbstractSession.java:3260)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabase(UnitOfWorkImpl.java:1403)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.commitToDatabase(RepeatableWriteUnitOfWork.java:547)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.commitToDatabaseWithChangeSet(UnitOfWorkImpl.java:1508)
	at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.issueSQLbeforeCompletion(UnitOfWorkImpl.java:3128)
	at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.issueSQLbeforeCompletion(RepeatableWriteUnitOfWork.java:268)
	at org.eclipse.persistence.transaction.AbstractSynchronizationListener.beforeCompletion(AbstractSynchronizationListener.java:157)
	at org.eclipse.persistence.transaction.JTASynchronizationListener.beforeCompletion(JTASynchronizationListener.java:68)
	at com.sun.jts.jta.SynchronizationImpl.before_completion(SynchronizationImpl.java:99)
	at com.sun.jts.CosTransactions.RegisteredSyncs.distributeBefore(RegisteredSyncs.java:158)
	at com.sun.jts.CosTransactions.TopCoordinator.beforeCompletion(TopCoordinator.java:2551)
	at com.sun.jts.CosTransactions.CoordinatorTerm.commit(CoordinatorTerm.java:278)
	at com.sun.jts.CosTransactions.TerminatorImpl.commit(TerminatorImpl.java:251)
	at com.sun.jts.CosTransactions.CurrentImpl.commit(CurrentImpl.java:623)
	at com.sun.jts.jta.TransactionManagerImpl.commit(TransactionManagerImpl.java:318)
	at com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate.commitDistributedTransaction(JavaEETransactionManagerJTSDelegate.java:160)
	at com.sun.enterprise.transaction.JavaEETransactionManagerSimplified.commit(JavaEETransactionManagerSimplified.java:843)
	at com.sun.ejb.containers.BaseContainer.completeNewTx(BaseContainer.java:5040)
	at com.sun.ejb.containers.BaseContainer.postInvokeTx(BaseContainer.java:4819)
	at com.sun.ejb.containers.AbstractSingletonContainer.createSingletonEJB(AbstractSingletonContainer.java:538)
	at com.sun.ejb.containers.AbstractSingletonContainer.access$100(AbstractSingletonContainer.java:74)
	at com.sun.ejb.containers.AbstractSingletonContainer$SingletonContextFactory.create(AbstractSingletonContainer.java:696)
	at com.sun.ejb.containers.AbstractSingletonContainer.instantiateSingletonInstance(AbstractSingletonContainer.java:444)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:213)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.initializeSingleton(SingletonLifeCycleManager.java:174)
	at org.glassfish.ejb.startup.SingletonLifeCycleManager.doStartup(SingletonLifeCycleManager.java:152)
	at org.glassfish.ejb.startup.EjbApplication.start(EjbApplication.java:150)
	at org.glassfish.internal.data.EngineRef.start(EngineRef.java:126)
	at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:241)
	at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:236)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:339)
	at com.sun.enterprise.v3.server.ApplicationLifecycle.deploy(ApplicationLifecycle.java:183)
	at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:272)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$1.execute(CommandRunnerImpl.java:305)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:320)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1176)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$900(CommandRunnerImpl.java:83)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1235)
	at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1224)
	at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:365)
	at com.sun.enterprise.v3.admin.AdminAdapter.service(AdminAdapter.java:204)
	at com.sun.grizzly.tcp.http11.GrizzlyAdapter.service(GrizzlyAdapter.java:166)
	at com.sun.enterprise.v3.server.HK2Dispatcher.dispath(HK2Dispatcher.java:100)
	at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:245)
	at com.sun.grizzly.http.ProcessorTask.invokeAdapter(ProcessorTask.java:791)
	at com.sun.grizzly.http.ProcessorTask.doProcess(ProcessorTask.java:693)
	at com.sun.grizzly.http.ProcessorTask.process(ProcessorTask.java:954)
	at com.sun.grizzly.http.DefaultProtocolFilter.execute(DefaultProtocolFilter.java:170)
	at com.sun.grizzly.DefaultProtocolChain.executeProtocolFilter(DefaultProtocolChain.java:135)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:102)
	at com.sun.grizzly.DefaultProtocolChain.execute(DefaultProtocolChain.java:88)
	at com.sun.grizzly.http.HttpProtocolChain.execute(HttpProtocolChain.java:76)
	at com.sun.grizzly.ProtocolChainContextTask.doCall(ProtocolChainContextTask.java:53)
	at com.sun.grizzly.SelectionKeyContextTask.call(SelectionKeyContextTask.java:57)
	at com.sun.grizzly.ContextTask.run(ContextTask.java:69)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:330)
	at com.sun.grizzly.util.AbstractThreadPool$Worker.run(AbstractThreadPool.java:309)
	at java.lang.Thread.run(Thread.java:619)
Caused by: java.sql.SQLIntegrityConstraintViolationException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL101109154551780' defined on 'SOURCE'.
	at org.apache.derby.client.am.SQLExceptionFactory40.getSQLException(Unknown Source)
	at org.apache.derby.client.am.SqlException.getSQLException(Unknown Source)
	at org.apache.derby.client.am.PreparedStatement.executeUpdate(Unknown Source)
	at org.eclipse.persistence.internal.databaseaccess.DatabaseAccessor.executeDirectNoSelect(DatabaseAccessor.java:792)
	... 84 more
Caused by: org.apache.derby.client.am.SqlException: The statement was aborted because it would have caused a duplicate key value in a unique or primary key constraint or unique index identified by 'SQL101109154551780' defined on 'SOURCE'.
	at org.apache.derby.client.am.Statement.completeExecute(Unknown Source)
	at org.apache.derby.client.net.NetStatementReply.parseEXCSQLSTTreply(Unknown Source)
	at org.apache.derby.client.net.NetStatementReply.readExecute(Unknown Source)
	at org.apache.derby.client.net.StatementReply.readExecute(Unknown Source)
	at org.apache.derby.client.net.NetPreparedStatement.readExecute_(Unknown Source)
	at org.apache.derby.client.am.PreparedStatement.readExecute(Unknown Source)
	at org.apache.derby.client.am.PreparedStatement.flowExecute(Unknown Source)
	at org.apache.derby.client.am.PreparedStatement.executeUpdateX(Unknown Source)
	... 86 more




This is my persistence xml
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
	xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
	<persistence-unit name="Gotware-jpa">
		<jta-data-source>jdbc/gottexDataSource</jta-data-source>
		<class>gotware.finance.ois.Ois</class>
		<class>gotware.finance.ois.EoniaSwap</class>
		<class>gotware.finance.fra.ForwardRateAgreement</class>
		<class>gotware.finance.euribors.Euribor</class>
		<class>gotware.finance.curves.Curve</class>
		<class>gotware.finance.currency.Currency</class>
		<class>gotware.finance.base.Security</class>
		<class>gotware.finance.curves.CurvePoint</class>
		<class>gotware.finance.base.Source</class>
		<class>gotware.dataobject.messaging.MessagingInformationHolder</class>
		<exclude-unlisted-classes>false</exclude-unlisted-classes>
		<shared-cache-mode>NONE</shared-cache-mode>

		<properties>

			<property name="eclipselink.logging.thread" value="true" />
			<property name="eclipselink.logging.timestamp" value="true" />
			<property name="eclipselink.logging.exceptions" value="true" />
			<property name="eclipselink.logging.connection" value="true" />
			<property name="eclipselink.logging.level" value="FINEST" />
			<property name="eclipselink.weaving.fetchgroups" value="true"/>
		</properties>
	</persistence-unit>
</persistence>


Any idea? Is there an error in how the CascadeTypes are set??

Best Regards
Edmondo Porcu
Re: em.persist trigger duplicate insertion [message #638225 is a reply to message #638162] Wed, 10 November 2010 10:02 Go to previous message
Chris Delahunt is currently offline Chris Delahunt
Messages: 995
Registered: July 2009
Senior Member
No, not a cascade setting problem. The error is saying there is a problem with the insert statement:
"INSERT IGNORE INTO SOURCE (TICKERNAME, DATAPROVIDER, PRIORITY, SECURITY_NAME) VALUES (?, ?, ?, ?)
bind => [EUSWE1Z Curncy, 0, 0, Eonia 1 month swap]" due to the 'SQL101109154551780' constraint being violated. You will need to check the database to see what the 'SQL101109154551780' constraint is, but I would check what the Source table primary keys are, and that a row with TICKERNAME = "EUSWE1Z Curncy" does not already exist, or that there aren't unique constraints on the DATAPROVIDER or PRIORITY fields.

Best Regards,
Chris
Previous Topic:CriteriaBuilder and ManyToOne Entity
Next Topic:Inheritance bug?: super class instantiated instead of sub class
Goto Forum:
  


Current Time: Wed Apr 16 12:16:59 EDT 2014

Powered by FUDForum. Page generated in 0.02849 seconds