Hallo.
Ich weiß nicht wo der Fehler liegt…
Folgende Konfiguration ist nur ein Test um mit Hibernate ein bisschen warm zu werden.
Hier die Datenbank.
Hier das sql Script für die Erstellung.
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,ALLOW_INVALID_DATES';
DROP SCHEMA IF EXISTS `formulare_dummy` ;
CREATE SCHEMA IF NOT EXISTS `formulare_dummy` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ;
USE `formulare_dummy` ;
-- -----------------------------------------------------
-- Table `formulare_dummy`.`Adresse`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `formulare_dummy`.`Adresse` ;
CREATE TABLE IF NOT EXISTS `formulare_dummy`.`Adresse` (
`idAdresse` INT NOT NULL AUTO_INCREMENT ,
`Strasse` VARCHAR(45) NOT NULL ,
`Ort` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`idAdresse`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `formulare_dummy`.`Person`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `formulare_dummy`.`Person` ;
CREATE TABLE IF NOT EXISTS `formulare_dummy`.`Person` (
`idPerson` INT NOT NULL AUTO_INCREMENT ,
`Name` VARCHAR(255) NOT NULL ,
`Adresse_idAdresse` INT NOT NULL ,
PRIMARY KEY (`idPerson`) ,
INDEX `fk_Person_Adresse_idx` (`Adresse_idAdresse` ASC) ,
CONSTRAINT `fk_Person_Adresse`
FOREIGN KEY (`Adresse_idAdresse` )
REFERENCES `formulare_dummy`.`Adresse` (`idAdresse` )
ON DELETE NO ACTION
ON UPDATE NO ACTION)
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `formulare_dummy`.`merkmale`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `formulare_dummy`.`merkmale` ;
CREATE TABLE IF NOT EXISTS `formulare_dummy`.`merkmale` (
`idmerkmale` INT NOT NULL AUTO_INCREMENT ,
`merkmal` VARCHAR(45) NOT NULL ,
PRIMARY KEY (`idmerkmale`) )
ENGINE = InnoDB;
-- -----------------------------------------------------
-- Table `formulare_dummy`.`Person_has_merkmale`
-- -----------------------------------------------------
DROP TABLE IF EXISTS `formulare_dummy`.`Person_has_merkmale` ;
CREATE TABLE IF NOT EXISTS `formulare_dummy`.`Person_has_merkmale` (
`Person_idPerson` INT NOT NULL ,
`merkmale_idmerkmale` INT NOT NULL ,
PRIMARY KEY (`Person_idPerson`, `merkmale_idmerkmale`) ,
INDEX `fk_Person_has_merkmale_merkmale1_idx` (`merkmale_idmerkmale` ASC) ,
INDEX `fk_Person_has_merkmale_Person1_idx` (`Person_idPerson` ASC) ,
CONSTRAINT `fk_Person_has_merkmale_Person1`
FOREIGN KEY (`Person_idPerson` )
REFERENCES `formulare_dummy`.`Person` (`idPerson` )
ON DELETE NO ACTION
ON UPDATE NO ACTION,
CONSTRAINT `fk_Person_has_merkmale_merkmale1`
FOREIGN KEY (`merkmale_idmerkmale` )
REFERENCES `formulare_dummy`.`merkmale` (`idmerkmale` )
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;
-- -----------------------------------------------------
-- Data for table `formulare_dummy`.`Adresse`
-- -----------------------------------------------------
START TRANSACTION;
USE `formulare_dummy`;
INSERT INTO `formulare_dummy`.`Adresse` (`idAdresse`, `Strasse`, `Ort`) VALUES (1, 'Kapellenweg', 'Stadt1');
INSERT INTO `formulare_dummy`.`Adresse` (`idAdresse`, `Strasse`, `Ort`) VALUES (2, 'Altwasser', 'Stadt2');
COMMIT;
-- -----------------------------------------------------
-- Data for table `formulare_dummy`.`Person`
-- -----------------------------------------------------
START TRANSACTION;
USE `formulare_dummy`;
INSERT INTO `formulare_dummy`.`Person` (`idPerson`, `Name`, `Adresse_idAdresse`) VALUES (1, 'Mario', 1);
INSERT INTO `formulare_dummy`.`Person` (`idPerson`, `Name`, `Adresse_idAdresse`) VALUES (2, 'Juliane', 1);
INSERT INTO `formulare_dummy`.`Person` (`idPerson`, `Name`, `Adresse_idAdresse`) VALUES (3, 'Klara', 2);
COMMIT;
-- -----------------------------------------------------
-- Data for table `formulare_dummy`.`merkmale`
-- -----------------------------------------------------
START TRANSACTION;
USE `formulare_dummy`;
INSERT INTO `formulare_dummy`.`merkmale` (`idmerkmale`, `merkmal`) VALUES (1, 'nett');
INSERT INTO `formulare_dummy`.`merkmale` (`idmerkmale`, `merkmal`) VALUES (2, 'böse');
INSERT INTO `formulare_dummy`.`merkmale` (`idmerkmale`, `merkmal`) VALUES (3, 'unruhig');
INSERT INTO `formulare_dummy`.`merkmale` (`idmerkmale`, `merkmal`) VALUES (4, 'klug');
COMMIT;
-- -----------------------------------------------------
-- Data for table `formulare_dummy`.`Person_has_merkmale`
-- -----------------------------------------------------
START TRANSACTION;
USE `formulare_dummy`;
INSERT INTO `formulare_dummy`.`Person_has_merkmale` (`Person_idPerson`, `merkmale_idmerkmale`) VALUES (1, 1);
INSERT INTO `formulare_dummy`.`Person_has_merkmale` (`Person_idPerson`, `merkmale_idmerkmale`) VALUES (1, 2);
INSERT INTO `formulare_dummy`.`Person_has_merkmale` (`Person_idPerson`, `merkmale_idmerkmale`) VALUES (2, 2);
INSERT INTO `formulare_dummy`.`Person_has_merkmale` (`Person_idPerson`, `merkmale_idmerkmale`) VALUES (3, 1);
INSERT INTO `formulare_dummy`.`Person_has_merkmale` (`Person_idPerson`, `merkmale_idmerkmale`) VALUES (3, 3);
COMMIT;
Hier die hibernate.cfg.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://184.25.16.3:3306/formulare_dummy</property>
<property name="hibernate.connection.username">wenger</property>
<property name="hibernate.connection.password">schwertfisch</property>
<property name="hibernate.show_sql">true</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
<mapping resource="test/Adresse.hbm.xml"/>
<mapping resource="test/Person.hbm.xml"/>
<mapping resource="test/Merkmale.hbm.xml"/>
</session-factory>
</hibernate-configuration>
Hier das Mapping der beiden relevanten Klassen-Tabellen.
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 05.08.2013 12:41:56 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="test.Merkmale" table="merkmale" catalog="formulare_dummy">
<id name="idmerkmale" type="java.lang.Integer">
<column name="idmerkmale" />
<generator class="identity" />
</id>
<property name="merkmal" type="string">
<column name="merkmal" length="45" not-null="true" />
</property>
<set name="persons" inverse="false" table="Person_has_merkmale">
<key>
<column name="merkmale_idmerkmale" not-null="true" />
</key>
<many-to-many entity-name="test.Person">
<column name="Person_idPerson" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated 05.08.2013 12:41:56 by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="test.Person" table="Person" catalog="formulare_dummy">
<id name="idPerson" type="java.lang.Integer">
<column name="idPerson" />
<generator class="identity" />
</id>
<many-to-one name="adresse" class="test.Adresse" fetch="select">
<column name="Adresse_idAdresse" not-null="true" />
</many-to-one>
<property name="name" type="string">
<column name="Name" not-null="true" />
</property>
<set name="merkmales" inverse="false" table="Person_has_merkmale">
<key>
<column name="Person_idPerson" not-null="true" />
</key>
<many-to-many entity-name="test.Merkmale">
<column name="merkmale_idmerkmale" not-null="true" />
</many-to-many>
</set>
</class>
</hibernate-mapping>
Und hier der Fehler bei einer einfachen Abfrage.
Wenn ich die many-to-many weglasse, funktioniert alles wie es sollte.
Sieht jemand den Fehler. Hilfe!
DAnke.
P.S. weil es vielleicht eine Rolle spielt. NetBeans7.x, MySQL5.5, Hibernate3.2.5, TableEngine InnoDB