JPAControllers from entities not working for parent-child create - java

I have a parent and child table.
schema: parent(int id,varchar desc), child(int id, varchar desc, int parent_id(foreignKey)).
From this I created entities and then JPAControllers from those entities using netbeans.
When I tried to store a parent with a collection of child it throws java.lang.IllegalArgumentException: An instance of a null PK has been incorrectly provided for this find operation.. After inspecting the JPA controllers generated by netbeans, I found out that they are assuming that the child objects in the parent have an ID and in my case since the child objects are also new I don't have an ID for them. But what I don't understand is that why the following code is present in the netbeans generated JPAController code.
Collection<Child> attachedChildCollection = new ArrayList<Child>();
for (Child childCollectionChildToAttach : parent.getChildCollection()) {
childCollectionChildToAttach = em.getReference(childCollectionChildToAttach.getClass(), childCollectionChildToAttach.getId());
attachedChildCollection.add(childCollectionChildToAttach);
}
parent.setChildCollection(attachedChildCollection);
Does anybody know any way to solve this other than manually editing JPAControllers.
Below code snippet shows how I tried to store parent.
Parent parentObj = new Parent();
parentObj.setDesc("parent");
Collection<Child> childCollection = new ArrayList<>();
Child childObj = new Child();
childObj.setDesc("child1");
childCollection.add(childObj);
Child childObj2 = new Child();
childCollection.add("childObj2");
parentObj.setChildCollection(childCollection);
parentJpaController.create(parentObj);
script for creating tables given below
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';
CREATE SCHEMA IF NOT EXISTS `mydb` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `mydb` ;
-- -----------------------------------------------------
-- Table `mydb`.`PARENT`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`PARENT` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`DESC` VARCHAR(45) NULL ,
PRIMARY KEY (`ID`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `mydb`.`CHILD`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `mydb`.`CHILD` (
`ID` INT NOT NULL AUTO_INCREMENT ,
`DESC` VARCHAR(45) NULL ,
`PARENT` INT NOT NULL ,
PRIMARY KEY (`ID`) ,
INDEX `FK_CHILD_PARENT` (`PARENT` ASC) ,
CONSTRAINT `FK_CHILD_PARENT`
FOREIGN KEY (`PARENT` )
REFERENCES `mydb`.`PARENT` (`ID` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
SET SQL_MODE=#OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=#OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=#OLD_UNIQUE_CHECKS;

Related

Unidirectionnel relationship : Remove cascade

I have two tables :
CREATE TABLE IF NOT EXISTS `DB`.`global_history` (
`ID` INT(11) AUTO_INCREMENT,
`ID_HISTORY` INT(11) NULL,
PRIMARY KEY (`ID`),
CONSTRAINT `FK_HISTORY_GLOBAL_HISTORY`
FOREIGN KEY (`ID_HISTORY`)
REFERENCES `DB`.`history` (`ID`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
Second table :
CREATE TABLE IF NOT EXISTS `DB`.`history` (
`ID` INT(11) AUTO_INCREMENT,
`TIMESTAMP` DATETIME NOT NULL,
PRIMARY KEY (`ID`));
but when I try to delete a row in History (Second table) I get this error :
--> Cannot delete or update a parent row : a foreign key constraint fails
And I want the relationship to be #ManyToOne So when I remove a row from global_history it will not remove any row from history
And this is my model class :
Global history :
#ManyToOne
#JoinColumn(name = "ID_HISTORY", nullable = true)
private History history;
--> history is a simple class
when you define a F.K from a child (global_history) to parent (History table), child table can not has invalid F.K. so you should decide for deleting parent which cause F.K will be invalid.
a foreign key with cascade delete means that if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted. This is called a cascade delete in SQL Server.
so if you want to prevent deleting corresponding child rows , you can set null value or default value by using following command:
ON DELETE SET NULL
ON DELETE SET DEFAULT
this is complete format:
CREATE TABLE child_table
(
column1 datatype [ NULL | NOT NULL ],
column2 datatype [ NULL | NOT NULL ],
...
CONSTRAINT fk_name
FOREIGN KEY (child_col1, child_col2, ... child_col_n)
REFERENCES parent_table (parent_col1, parent_col2, ... parent_col_n)
ON DELETE CASCADE
[ ON UPDATE { NO ACTION | CASCADE | SET NULL | SET DEFAULT } ]
)
https://www.techonthenet.com/sql_server/foreign_keys/foreign_delete.php

MySQL. When trying to delete few duplicate rows, it deletes the last and does not delete any further

I've got tables Artist, Concert, and Artist_Concert, which contains many-to many connections between Artist and Concert.
The problem is: after adding a Concert with few Artists, when trying to delete rows from Artist_Concert, it only deletes only one row and nothing happens when trying to delete any others.
This is how I'm trying to delete rows in Java:
stat = connect.createStatement();
res = stat.executeQuery ("SELECT idConcert FROM concerthall.concert where ConcertName = '"+conc+"';");
res.first();
int idconc = res.getInt(1);
stat.execute ("DELETE FROM concerthall.artist_concert WHERE idConc="+idconc+"");
Artist
CREATE TABLE IF NOT EXISTS `concerthall`.`Artist` (
`idArtist` INT NOT NULL AUTO_INCREMENT,
`ArtName` VARCHAR(45) NOT NULL,
`ArtFee` INT NULL,
PRIMARY KEY (`idArtist`))
ENGINE = InnoDB
Artist-Concert
CREATE TABLE IF NOT EXISTS `concerthall`.`Artist_Concert` (
`idCA` INT NOT NULL AUTO_INCREMENT,
`idArt` INT NOT NULL,
`IdConc` INT NOT NULL,
INDEX `idart_idx` (`idArt` ASC),
INDEX `idconc_idx` (`IdConc` ASC),
PRIMARY KEY (`idCA`),
CONSTRAINT `idart2`
FOREIGN KEY (`idArt`)
REFERENCES `concerthall`.`Artist` (`idArtist`)
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `idconct4`
FOREIGN KEY (`IdConc`)
REFERENCES `concerthall`.`Concert` (`idConcert`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
Concert
CREATE TABLE IF NOT EXISTS `concerthall`.`Concert` (
`idConcert` INT NOT NULL AUTO_INCREMENT,
`ConcertName` VARCHAR(45) NOT NULL,
`ConcertDateTime` DATETIME NOT NULL,
`Organizator` INT NOT NULL,
PRIMARY KEY (`idConcert`),
INDEX `concertorg_idx` (`Organizator` ASC),
CONSTRAINT `concertorg`
FOREIGN KEY (`Organizator`)
REFERENCES `concerthall`.`Organizator` (`idOrganizator`)
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB
The easiest way to drop duplicates is:
ALTER IGNORE TABLE table ADD UNIQUE INDEX( a, b );
In the INDEX() part, enter the name(s) of the column(s) you only want unique entries for. I think you want:
ALTER IGNORE TABLE concerthall.artist_concert ADD UNIQUE INDEX( idConc );
Then drop the index.

JDBC mysql meta.getExportedKeys() returning empty resultset

Hi I'm trying to get the foreig key for a given table, I'm using this code :
ResultSet rs = meta.getImportedKeys(_con.getCatalog(), null, _tableName);
while (rs.next())
{
//get the foreignKeys
}
ResultSet rs2 = meta.getExportedKeys(_con.getCatalog(), null, _tableName);
while (rs2.next())
{
//get the foreignKeys
}
The resultSet is empty, although the table contains a foreign key and is a foreign key to another table,
the getImportedKeys works fine.
Thanks for any suggestions.
Tables :
CREATE TABLE `COMMANDE` (
`COMMANDE_ID` int(11) NOT NULL,
`CLIENT_ID` int(100) DEFAULT NULL,
`TOURNEE_ID` int(100) DEFAULT NULL,
PRIMARY KEY (`COMMANDE_ID`),
KEY `CLIENT_ID` (`CLIENT_ID`),
KEY `TOURNEE_ID` (`TOURNEE_ID`),
CONSTRAINT `commande_ibfk_1` FOREIGN KEY (`CLIENT_ID`) REFERENCES `CLIENT` (`CLIENT_ID`),
CONSTRAINT `commande_ibfk_2` FOREIGN KEY (`TOURNEE_ID`) REFERENCES `TOURNEE` (`TOURNEE_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `CLIENT` (
`CLIENT_ID` int(100) NOT NULL,
`LIBELLE` varchar(100) DEFAULT NULL,
PRIMARY KEY (`CLIENT_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
I tried the code with both tables.
I think the problem is from the rather curious naming of the methods in JDBC, and the hard to grok description.
To get primary keys of a table, you should use getPrimaryKeys(), to get the foreign key of a table (and the primary key they reference), use getImportedKeys()
There are additional methods
- getExportedKeys() exposes the foreign keys that reference the specified table (so the table parameter specifies the table with the primary key)
- getCrossReference() is a combination of all of the above: you need to specify the tables on both sides of the constraint

How to get super table information in java?

My database had a lot of parent and child tables.The tables contains the foreign key which has the link with the parent table.I wants to get the information of parent table of the child table using java?How can I achieve that?
For ex,consider the student and mark table,
The student table contains the information like studentID,name.
studentID-Primary key
The marks table contains the markId,studentId,Sub1,sub2,sub3 etc
markId-Primarykey
studentID-Foreignkey refers Student table
My table creation queries are,
CREATE TABLE `Student12` (
`studentId` SMALLINT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(50) NOT NULL,
PRIMARY KEY (`studentId`)
)
ENGINE = InnoDB;
CREATE TABLE `Marks` (
`markId` SMALLINT NOT NULL AUTO_INCREMENT,
`subject1` SMALLINT NOT NULL,
`subject2` SMALLINT NOT NULL,
`studentId` SMALLINT NOT NULL,
PRIMARY KEY (`markId`),
CONSTRAINT `FK_Marks_Student` FOREIGN KEY `FK_Marks_Student` (`studentId`)
REFERENCES `Student12` (`studentId`)
ON DELETE RESTRICT
ON UPDATE RESTRICT
)
ENGINE = InnoDB;
If I give the mark table name as input, how can I get its parent or super table name student and information about student table?Any help should be appreciable.
It totally depends on the way tables are created. Foreign keys are not mandatory to create, they could be a simple column in one table with no explicit relationship to the other table. If you are very sure that the links are created explicitly (the foreign keys are defined) then you could use information_schema. But if there is no foreign key defined (which is true in most of the databases I have seen), then there is no way for you to find the links inside the database. You have to look into the code (if there is any available) and try to find a clue.
The JDBC DatasetMetaData interface provides a couple of methods that may help. (The following text is copied from the javadoc.
ResultSet getExportedKeys(String catalog, String schema, String table)
Retrieves a description of the foreign key columns that reference the given table's primary key columns (the foreign keys exported by a table).
ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, String foreignCatalog, String foreignSchema, String foreignTable)
Retrieves a description of the foreign key columns in the given foreign key table that reference the primary key or the columns representing a unique constraint of the parent table (could be the same or a different table).
Of course, these can only work if the relevant columns have been declared as foreign keys in the SQL table DDL.
You can use the DatabaseMetaData to retrieve informations about foreign keyes
and the referenced Tables. Im not sure if it works with all kinds of MySql Tables.
The principle is to use the follwing code (not tested) to retrieve information about the super tables
ResultSet rs = null;
DatabaseMetaData dm = conn.getMetaData( );
// get super tables of table marks
ResultSet rs = dm.getSuperTables( null , null, "marks" );
while( rs.next( ) ) {
System.out.println(String.format("Table Catalog %s", rs.getString("TABLE_CAT") );
System.out.println(String.format("Table Schema %s", rs.getString("TABLE_SCHEM") );
System.out.println(String.format("Table Name %s", rs.getString("TABLE_NAME") );
System.out.println(String.format("Table Name %s", rs.getString("SUPERTABLE_NAME") );
}
You can use thes informations to get additional informations about the referenced table
and the foreigen and referenced primary keys:
ResultSet rs = dm.getCrossReference( null , null , "student" , null , null , "marks" );
System.out.println(String.format("Exported Keys Info Table %s.", "marks"));
while( rs.next( ) ) {
String pkey = rs.getString("PKCOLUMN_NAME");
String ptab = rs.getString("PKTABLE_NAME");
String fkey = rs.getString("FKCOLUMN_NAME");
String ftab = rs.getString("FKTABLE_NAME");
System.out.println("primary key table = " + ptab);
System.out.println("primary key = " + pkey);
System.out.println("foreign key table = " + ftab);
System.out.println("foreign key = " + fkey);
}
And finally you can retrieve the information about the super table by
ResultSet rs = dm.getTables(null,null,"student" ,null);
System.out.println("Table name:");
while (rs.next()){
String table = rs.getString("TABLE_NAME");
System.out.println(table);
}

"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`) )
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;
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.

Categories