-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Help: Storing one object in two collections
PostPosted: Sun Aug 26, 2007 9:25 pm 
Newbie

Joined: Sun Aug 26, 2007 9:21 pm
Posts: 2
Hi folks,

Currently I'm trying to store one element/object in two collections.
According to the generated database schema this should work just fine.
However, if I don't reset the id of my object to null, it does not work.
There must be a way to 'store' exactly the same object within two collections ...

Ideas?


@Entity
public class Candle implements Comparable<Candle> {


private Long id;


public Candle() {
}


@Id @GeneratedValue
public Long getId() {
return id;
}


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

@MappedSuperclass
public abstract class Series<T> extends Vector<T> {

private Long id;

protected Series() {
}


@Id @GeneratedValue
public Long getId() {
return id;
}


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


@OneToMany(cascade=CascadeType.ALL)
@IndexColumn(name="id")
protected T[] getData() {
return Arrays.asArray(this, getChildClass());
}

protected void setData(T[] data) {
setData(Arrays.asList(data));
}

}

@Entity
public class CandleSeries extends Series<Candle> {
...
}


public static void main(String... args) {
// clear
candleDao.deleteAll();

// create objects
Candle candle = new Candle();
CandleSeries series1 = new CandleSeries(candle);
CandleSeries series2 = new CandleSeries(candle);

// save
candleDao.update(series1);
candleDao.update(series2);
}


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 'SQL070825051501951' defined on 'CANDLESERIES_CANDLE'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.TransactionResourceImpl.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeStatement(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedPreparedStatement.executeUpdate(Unknown Source)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:102)
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(NonBatchingBatcher.java:23)
at org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1146)
... 28 more
Caused by: java.sql.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 'SQL070825051501951' defined on 'CANDLESERIES_CANDLE'.
at org.apache.derby.impl.jdbc.SQLExceptionFactory.getSQLException(Unknown Source)
at org.apache.derby.impl.jdbc.SQLExceptionFactory40.wrapArgsForTransportAcrossDRDA(Unknown Source)
... 40 more


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 30, 2007 10:31 pm 
Newbie

Joined: Sun Aug 26, 2007 9:21 pm
Posts: 2
push


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.