Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple primary keys

I created database, for my android app, witch has 16 tables. I want to use ORMlite mapping. The problem is that I didn't find examples where you have composite id(Multiple primary keys). For example I have table:

CREATE  TABLE IF NOT EXISTS `Tourist_Guide`.`Cultural_activity` (
  `City_Id` INT NOT NULL ,
  `activity_Id` INT NOT NULL ,
  `Cultural_activity_Id` INT NOT NULL AUTO_INCREMENT ,
  `Name_Of_Cultural_activity` VARCHAR(30) NOT NULL ,
  PRIMARY KEY (`Cultural_activity_Id`, `City_Id`, `activity_Id`) ,
  INDEX `fk_Cultural_activity_activity1` (`City_Id` ASC, `activity_Id` ASC) ,
  CONSTRAINT `fk_Cultural_activity_activity1`
    FOREIGN KEY (`City_Id` , `activity_Id` )
    REFERENCES `Tourist_Guide`.`activity` (`City_Id` , `activity_Id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

Can you, please, tell me how to map this table to class(how this class should look like), is that even possible?

like image 713
sekula87 Avatar asked May 06 '12 09:05

sekula87


1 Answers

You have to use the following annotation above each unique field:

@DatabaseField (uniqueCombo = true)

Here are the docs on uniqueCombo.

like image 52
Zakaria Avatar answered Oct 05 '22 10:10

Zakaria