0

I have created an entity with composite primary key.

<entity entity-name="XXX" package-name="org.ofbiz.yyy">

<field name="F1" type="id-ne"></field>
<field name="F2" type="id-ne"></field>
<field name="F3" type="id-ne"></field>

<prim-key field="F1"/>
<prim-key field="F2"/>
</entity>

Here F2 is like sequence number. F1 can have same value with F2 changing.

Ex: F1    F2   F3
    abc   1    some text
    abc   2    some text

As i declared them as primary key, it should allow me to insert an entry like above. But i'm getting 'Duplicate entry for primary key F1' error while inserting second entry.

I searched here and there to know alternative method to define composite primary key but i didn't find any.

I have updated the primary key from single key to composite. Please help me in this issue. Thanks in advance.

Vamsi Krishna
  • 140
  • 1
  • 1
  • 6

1 Answers1

0

I found solution to my problem.

Actual problem is, initially i have created table with single primary key. Later i have updated table with composite primary key.

I think mysql is not updating meta info (or whatever it stores about table). Due to this, it considering the table with single primary key and throwing the duplicate entry for primary key error.

I have dropped that table and created again. Now, it allowing me to insert values like above example.

I think in ofbiz entitymodel.xml, if we update primary key combination we must clear tables info.

Thanks,

Vamsi Krishna
  • 140
  • 1
  • 1
  • 6