You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Fff <fi...@ticktech.bg> on 2017/11/29 15:16:08 UTC

sql insert with composite primary key

Hi, 

My POJO has composite primary key. 
e.g. 
public class TriggerDefinition {
    @Id
    private TriggerDefinitionKey triggerDefinitionKey;
} 

public TriggerDefinitionKey(Long triggerId, Long biEventId) {
        this.triggerId = triggerId;
        this.biEventId = biEventId;
    }

My question is - how can I define the _key when inserting with SQL query? I
try the following:
INSERT INTO TriggerDefinition (_KEY,TriggerId,BiEventId) values
(11,33,11,33); I did not find anything related to this.



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: sql insert with composite primary key

Posted by vkulichenko <va...@gmail.com>.
Then the insert syntax I provided should work.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: sql insert with composite primary key

Posted by Fff <fi...@ticktech.bg>.
HI,
Thanks for your help!
We define it using QueryEntity by providing 'keyFields' property:

<property name="keyFields">
                                    <set>
                                        
                                        <value>triggerId</value>
                                        <value>biEventId</value>
                                    </set>
  </property>



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/

Re: sql insert with composite primary key

Posted by vkulichenko <va...@gmail.com>.
Hi,

How do you define the schema? Using DDL or in CacheConfiguration?

Basically, you don't need to use _key at all here since TriggerId and
BiEventId actually compose the primary key. But you need to make sure Ignite
knows about that. For example, if you create a table like this:

CREATE TABLE TriggerDefinition (triggerId int, biEventId int, nonKeyField
int, PRIMARY KEY (triggerId, biEventId))

you can insert like this:

INSERT INTO TriggerDefinition (triggerId, biEventId, nonKeyField) VALUES
(10, 20, 30);

Ignite will automatically figure our which fields should go to key object,
and which ones to value object.

If you use QueryEntity to configure schema, provide key field names via
'keyFields' property.

-Val



--
Sent from: http://apache-ignite-users.70518.x6.nabble.com/