在NetBeans7中,当我尝试添加“数据库中的实体类”时,会出现以下问题:左侧的某些表格显示为灰色并标记为“(无主键)”,所以我无法添加它们。 实际上,主键是正确的。表 groups,groupsyear,specialization 表格是灰色的,其他所有表格都很好。
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`) )
ENGINE = 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;
为了更好地理解:http://i.stack.imgur.com/cGsjG.png
我希望有人会在架构中发现错误。
答案 0 :(得分:2)
我找到了答案。也许不是最好的,但感谢这个链接http://aquaryus.wordpress.com/2011/04/11/tutorial-create-a-quick-jee-web-service-with-mysql-and-netbeans-glassfish/我刚用MyISAM替换了引擎类型InnoDB,现在一切正常! (至少它允许为JPA创建正确的POJO)但是InnoDB无效的问题仍然存在。