开发者

"No primary keys" error in NetBeans

In NetBeans7 when I'm trying to add "Entity Classes from Database" the following problem occurs: some of the tables on the left are greyed out and marked "(no primary keys)", so I can't add them. Actually, the primary keys are correct. The tables groups, groupsyear, specialization are greyed, all others are fine.

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

DROP SCHEMA IF EXISTS `mydb` ;
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;

-- -----------------------------------------------------
-- Table `mydb`.`Faculty`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Faculty` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Faculty` (
  `idFaculty` INT NOT NULL ,
  `name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idFaculty`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Specialization`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Specialization` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Specialization` (
  `idSpecialization` INT NOT NULL ,
  `Faculty_idFaculty` INT NOT NULL ,
  `Name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idSpecialization`) ,
  CONSTRAINT `fk_Specialization_Faculty`
    FOREIGN KEY (`Faculty_idFaculty` )
    REFERENCES `mydb`.`Faculty` (`idFaculty` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Specialization_Faculty` ON `mydb`.`Specialization` (`Faculty_idFaculty` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`Student`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Student` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Student` (
  `idStudent` INT NOT NULL ,
  `Specialization_idSpecialization` INT NOT NULL ,
  `Name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idStudent`) ,
  CONSTRAINT `fk_Student_Specialization1`
    FOREIGN KEY (`Specialization_idSpecialization` )
    REFERENCES `mydb`.`Specialization` (`idSpecialization` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Student_Specialization1` ON `mydb`.`Student` (`Specialization_idSpecialization` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`Discipline`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Discipline` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Discipline` (
  `idDiscipline` INT NOT NULL ,
  `Name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idDiscipline`) )
ENGINE = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`Lecturer`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Lecturer` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Lecturer` (
  `idLecturer` INT NOT NULL ,
  `Name` VARCHAR(45) NOT NULL ,
  PRIMARY KEY (`idLecturer`) )
ENGIN开发者_开发知识库E = InnoDB;


-- -----------------------------------------------------
-- Table `mydb`.`GroupsYear`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`GroupsYear` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`GroupsYear` (
  `idGroupsYear` INT NOT NULL ,
  `Discipline_idDiscipline` INT NOT NULL ,
  `Lecturer_idLecturer` INT NOT NULL ,
  `Year` YEAR NOT NULL ,
  PRIMARY KEY (`idGroupsYear`) ,
  CONSTRAINT `fk_Groups_Year_Discipline1`
    FOREIGN KEY (`Discipline_idDiscipline` )
    REFERENCES `mydb`.`Discipline` (`idDiscipline` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_GroupsYear_Lecturer1`
    FOREIGN KEY (`Lecturer_idLecturer` )
    REFERENCES `mydb`.`Lecturer` (`idLecturer` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Groups_Year_Discipline1` ON `mydb`.`GroupsYear` (`Discipline_idDiscipline` ASC) ;

CREATE INDEX `fk_GroupsYear_Lecturer1` ON `mydb`.`GroupsYear` (`Lecturer_idLecturer` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`Groups`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Groups` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Groups` (
  `idGroups` INT NOT NULL ,
  `GroupsYear_idGroupsYear` INT NOT NULL ,
  `Lecturer_idLecturer` INT NOT NULL ,
  PRIMARY KEY (`idGroups`) ,
  CONSTRAINT `fk_Group_GroupsYear1`
    FOREIGN KEY (`GroupsYear_idGroupsYear` )
    REFERENCES `mydb`.`GroupsYear` (`idGroupsYear` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Group_Lecturer1`
    FOREIGN KEY (`Lecturer_idLecturer` )
    REFERENCES `mydb`.`Lecturer` (`idLecturer` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Group_GroupsYear1` ON `mydb`.`Groups` (`GroupsYear_idGroupsYear` ASC) ;

CREATE INDEX `fk_Group_Lecturer1` ON `mydb`.`Groups` (`Lecturer_idLecturer` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`Current_Group_has_Student`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Current_Group_has_Student` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Current_Group_has_Student` (
  `Groups_idGroups` INT NOT NULL ,
  `Student_idStudent` INT NOT NULL ,
  PRIMARY KEY (`Groups_idGroups`, `Student_idStudent`) ,
  CONSTRAINT `fk_Groups_has_Student_Groups1`
    FOREIGN KEY (`Groups_idGroups` )
    REFERENCES `mydb`.`Groups` (`idGroups` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Groups_has_Student_Student1`
    FOREIGN KEY (`Student_idStudent` )
    REFERENCES `mydb`.`Student` (`idStudent` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Groups_has_Student_Student1` ON `mydb`.`Current_Group_has_Student` (`Student_idStudent` ASC) ;

CREATE INDEX `fk_Groups_has_Student_Groups1` ON `mydb`.`Current_Group_has_Student` (`Groups_idGroups` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`LongTimeAgo_Group_has_Student`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`LongTimeAgo_Group_has_Student` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`LongTimeAgo_Group_has_Student` (
  `Groups_idGroups` INT NOT NULL ,
  `Student_idStudent` INT NOT NULL ,
  PRIMARY KEY (`Groups_idGroups`, `Student_idStudent`) ,
  CONSTRAINT `fk_Groups_has_Student_Groups2`
    FOREIGN KEY (`Groups_idGroups` )
    REFERENCES `mydb`.`Groups` (`idGroups` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Groups_has_Student_Student2`
    FOREIGN KEY (`Student_idStudent` )
    REFERENCES `mydb`.`Student` (`idStudent` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Groups_has_Student_Student2` ON `mydb`.`LongTimeAgo_Group_has_Student` (`Student_idStudent` ASC) ;

CREATE INDEX `fk_Groups_has_Student_Groups2` ON `mydb`.`LongTimeAgo_Group_has_Student` (`Groups_idGroups` ASC) ;


-- -----------------------------------------------------
-- Table `mydb`.`Past_Group_has_Student`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `mydb`.`Past_Group_has_Student` ;

CREATE  TABLE IF NOT EXISTS `mydb`.`Past_Group_has_Student` (
  `Groups_idGroups` INT NOT NULL ,
  `Student_idStudent` INT NOT NULL ,
  PRIMARY KEY (`Groups_idGroups`, `Student_idStudent`) ,
  CONSTRAINT `fk_Groups_has_Student_Groups3`
    FOREIGN KEY (`Groups_idGroups` )
    REFERENCES `mydb`.`Groups` (`idGroups` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_Groups_has_Student_Student3`
    FOREIGN KEY (`Student_idStudent` )
    REFERENCES `mydb`.`Student` (`idStudent` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;

CREATE INDEX `fk_Groups_has_Student_Student3` ON `mydb`.`Past_Group_has_Student` (`Student_idStudent` ASC) ;

CREATE INDEX `fk_Groups_has_Student_Groups3` ON `mydb`.`Past_Group_has_Student` (`Groups_idGroups` ASC) ;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;

For better understanding: http://i.stack.imgur.com/cGsjG.png

I hope someone will find a mistake in schema.


I've found the answer. Maybe not the best one, but thanks to this link http://aquaryus.wordpress.com/2011/04/11/tutorial-create-a-quick-jee-web-service-with-mysql-and-netbeans-glassfish/ I just replaced engine type InnoDB with MyISAM and everything now works fine! (at least it allows to create correct POJOs for JPA) But the question why InnoDB doesn't work is still open.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜