DB_FOREIGN_CONFLICT

Just for testing BDB with Concurrent Data Store and the DPL features I-ve setup a very simple java program, composed by 3 classes:
******************* EntityT1.java
package test;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;
@Entity
public class EntityT1 {
private EntityT1() {}
public EntityT1(String name) {
this.name = name;
// The primary key must be unique in the database.
@PrimaryKey(sequence="ID1")
private int primaryKey1;
@SecondaryKey(relate=Relationship.MANY_TO_ONE)
String name;
public String getName() {
return name;
public void setName(String name) {
this.name = name;
public int getPrimaryKey1() {
return primaryKey1;
@Override
public String toString() {
return "EntityT1 [primaryKey1=" + primaryKey1 + ", name=" + name + "]";
******************* EntityT2.java
package test;
import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.SecondaryKey;
import com.sleepycat.persist.model.Relationship;;
@Entity
public class EntityT2 {
private EntityT2() { }
public EntityT2(int id1,String description) {
this.description = description;
foreignKey=id1;
// The primary key must be unique in the database.
@PrimaryKey(sequence = "ID2")
private int primaryKey2;
@SecondaryKey(relate=Relationship.MANY_TO_ONE,relatedEntity=EntityT1.class)
private int foreignKey;
String description;
public int getForeignKey() {
return foreignKey;
public void setForeignKey(int foreignKey) {
this.foreignKey = foreignKey;
public String getDescription() {
return description;
public void setDescription(String description) {
this.description = description;
public int getPrimaryKey2() {
return primaryKey2;
@Override
public String toString() {
return "EntityT2 [primaryKey2=" + primaryKey2 + ", foreignKey=" + foreignKey + ", description=" + description + "]";
******************* TestMain.java
package test;
import java.io.File;
import java.io.FileNotFoundException;
import com.sleepycat.db.DatabaseException;
import com.sleepycat.db.Environment;
import com.sleepycat.db.EnvironmentConfig;
import com.sleepycat.persist.EntityStore;
import com.sleepycat.persist.PrimaryIndex;
import com.sleepycat.persist.StoreConfig;
public class TestMain {
public static void main(String[] args) {
File dbEnvPathFile = new File("/var/tmp/dbEnv");
try {
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setInitializeCache(true);
envConfig.setInitializeCDB(true);
Environment dbEnvironment = new Environment(dbEnvPathFile, envConfig);
StoreConfig t1Config = new StoreConfig();
t1Config.setAllowCreate(true);
EntityStore t1Store = new EntityStore(dbEnvironment, "T1", t1Config);
PrimaryIndex<Integer, EntityT1> t1pidx = t1Store.getPrimaryIndex(Integer.class, EntityT1.class);
EntityT1 t1 = new EntityT1("T1");
System.out.println(t1);
t1pidx.putNoOverwrite(t1);
System.out.println(t1);
StoreConfig t2Config = new StoreConfig();
t2Config.setAllowCreate(true);
EntityStore t2Store = new EntityStore(dbEnvironment, "T2", t2Config);
PrimaryIndex<Integer, EntityT2> t2pidx = t2Store.getPrimaryIndex(Integer.class, EntityT2.class);
EntityT2 t2 = new EntityT2(t1.getPrimaryKey1(),"T2");
System.out.println(t2);
t2pidx.putNoOverwrite(t2);
System.out.println(t2);
t1Store.close();
t2Store.close();
dbEnvironment.close();
} catch (DatabaseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (FileIsNotDirectoryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (CannotDeleteFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
I ran into two problems:
1) first just using "put()" method for storing records doesn't work, I get the "Operation not permitted: Write attempted on read-only cursor: Operation not permitted" exception, so I had to use putNoReturn or putNoOverwrite (for some reason these work.
2) the first put works well, but then the second fails with this exception: "DB_FOREIGN_CONFLICT: A foreign database constraint has been violated: DB_FOREIGN_CONFLICT: A foreign database constraint has been violated".
No way to understand/fix one ot both the problems. Can anybody explain where I'm doing wrong ?
Thanks

Hi,
Thank you for trying/using BDB.
Item 1 is a bug, and we are fixing it(It only affects CDS, and if you use TDS, it will be not a problem).
About item2, the failure is caused by incorrect use of foreign key constraint. According to http://www.oracle.com/technology/documentation/berkeley-db/db/gsg/JAVA/dplindexcreate.html#foreignkey , the related indexes should be in the same EntityStore. So, in the sample code, if you put t1pidx and t2pidx both in t1Store or(exclusive-or) t2Store, the PrimaryIndex.putNoOverwrite will work as expect.
Regards,
--Winter
Edited by: Winter on 2010-5-20 下午5:21

Similar Messages

Maybe you are looking for

  • How do I change the page it goes to win opening a new tab?

    Okay. So I recently downloaded something that made my new tab into a Bing thing. That's not very descriptive, so... Basically when I used to open a tab, it would just be a blank, white page. But after downloading Gimp 2, an editing software, it also

  • Preventing the creation of direct PO

    Hi there experts, I would like to know if there is some way to prevent the creation of direct PO. I want that the PO is always created with reference to a PR or a contract. Tanks in advance

  • The Itunes will not update to the newest version of Itunes?

    I did all my updates for Windows. I deleted the 'temp' file. I am not getting an error message I will just try to download it through the apple website and it does nothing, or through my itunes and the bar pops up for like a milisecond and dissapears

  • Imported pdf _ fonts don't print correctly from CS3

    When I place a pdf file in InDesign CS3 and I imageset it on an Agfa Selectset, some fonts get squished together. InDesign CS2 prints ok, though. How come?

  • Are there digital versions of CIB for Premiere Pro and InDesign?

    As I travel quite a bit, I am finding that lugging around these two books is just more heavy baggage. I looked on the net but cannot find any digital versions in a straight PDF file, (not kindle or ibook). Does anyone know if Adobe has this available