-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: many-to-one & violates foreign key constraint
PostPosted: Wed Jul 28, 2004 1:26 pm 
Beginner
Beginner

Joined: Sun Apr 04, 2004 8:45 am
Posts: 20
Hi!

I have the classes Aufsicht and Pruefung:


| Pruefung | 1 -------------------- 1 .. * | Aufsicht |


and the following mapping files:

File Aufsicht.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
   <class name="ch.fhz.hsw.hibernate.model.Aufsicht" table="t_aufsichten">
      <id name="aufsichtId" type="long" unsaved-value="null" >
         <column name="AUFSICHT_ID" sql-type="integer" not-null="true"/>
         <generator class="hilo"/>
      </id>
      <!-- Liste der Aufsichpersonen -->
      <list name="aufsichtpersonenListe" table="t_dozierende_aufsichten"
         cascade="none" lazy="true">
         <key column="AUFSICHT_ID" />
         <index column="LIST_INDEX" type="integer" />
         <many-to-many class="ch.fhz.hsw.hibernate.model.Dozent"
            column="DOZIERENDE_ID" />
      </list>
      <!-- Bidirektionale Assoziation zur Pruefung -->
      <many-to-one name="pruefung"
         class="ch.fhz.hsw.hibernate.model.Pruefung" cascade="none"
         column="PRUEFUNG_ID" />
   </class>
</hibernate-mapping>


File Pruefung.hbm.xml

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
    PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
   <hibernate-mapping>
      <class name="ch.fhz.hsw.hibernate.model.Pruefung" table="t_pruefungen">
      <id name="pruefungId" type="long" unsaved-value="null" >
         <column name="PRUEFUNG_ID" sql-type="integer" not-null="true"/>
         <generator class="hilo"/>
      </id>
      <!-- Datum -->
      <property name="datum">
         <column not-null="true" sql-type="TIMESTAMP" name="DATUM" />
      </property>
      <!-- Klassenraumliste (Pruefungsraeume) -->
      <list name="klassenraumListe" cascade="none" lazy="true">
         <key column="PRUEFUNG_ID" />
         <index column="LIST_INDEX" type="integer" />
         <one-to-many class="ch.fhz.hsw.hibernate.model.Klassenraum"/>
      </list>
      <!-- Aufsichtenliste -->
      <list name="aufsichtenListe" cascade="none" lazy="true">
         <key column="AUFSICHT_ID" />
         <index column="LIST_INDEX" type="integer" />
         <one-to-many class="ch.fhz.hsw.hibernate.model.Aufsicht"/>
      </list>
      <!-- Liste der Anmeldungen -->
      <list name="anmeldungListe" cascade="none" lazy="true">
         <key column="ANMELDUNG_ID" />
         <index column="LIST_INDEX" type="integer" />
         <one-to-many class="ch.fhz.hsw.hibernate.model.Anmeldung" />
      </list>
      <!-- Liste der Faecher -->
      <list name="faecherListe" cascade="none" lazy="true">
         <key column="FACH_ID" />
         <index column="LIST_INDEX" type="integer" />
         <one-to-many class="ch.fhz.hsw.hibernate.model.Fach"/>
      </list>
      <!-- Beschreibung -->
      <property name="beschreibung">
         <column not-null="false" sql-type="varchar(256)" name="BESCHREIBUNG" />
      </property>
   </class>
</hibernate-mapping>


The SchemaExport create follwing Schema-File:
Code:
alter table t_dozierende drop constraint FK5A46C73CC3912989
alter table t_faecher drop constraint FK7A917D11E9B1835A
alter table t_dozierende_faecher drop constraint FKF228FBD9C3912989
alter table t_dozierende_faecher drop constraint FKF228FBD983CC52FE
alter table t_dozierende_faecher drop constraint FKF228FBD9E9B1835A
alter table t_klassenraeume drop constraint FKB9A613D5DD509A0
alter table t_dozierende_aufsichten drop constraint FKF717FEF3C3912989
alter table t_dozierende_aufsichten drop constraint FKF717FEF3AF45A933
alter table t_anmeldungen drop constraint FK6FE58A2F8FFE823B
alter table t_anmeldungen drop constraint FK6FE58A2F3BCC3F29BC6B19BC
alter table t_anmeldungen drop constraint FK6FE58A2F3BCC3F29
alter table t_aufsichten drop constraint FKF06D52BBAF45A933
alter table t_aufsichten drop constraint FKF06D52BBDD509A0
alter table t_studierende drop constraint FK3EC8F0C5492C73CA
alter table t_reservierungen drop constraint FKD39F37F5A0C5D5B9
drop table t_dozierende
drop table t_faecher
drop table t_dozierende_faecher
drop table t_klassenraeume
drop table t_dozierende_aufsichten
drop table t_anmeldungen
drop table t_aufsichten
drop table t_studierende
drop table t_reservierungen
drop table t_pruefungen
drop table t_personen
drop table t_adressen
drop table hibernate_unique_key
create table t_dozierende (
   DOZIERENDE_ID INT8 not null,
   primary key (DOZIERENDE_ID)
)
create table t_faecher (
   ID integer not null,
   FACHNAME varchar(32) not null,
   FACH_ID INT8,
   LIST_INDEX INT4,
   primary key (ID)
)
create table t_dozierende_faecher (
   DOZIERENDE_ID INT8 not null,
   FACH_ID INT8 not null,
   LIST_INDEX INT4 not null,
   DOZENT_ID INT8 not null,
   primary key (FACH_ID, LIST_INDEX)
)
create table t_klassenraeume (
   KLASSENRAUM_ID integer not null,
   BEZEICHNUNG varchar(32) not null,
   ANZAHL_PLAETZE integer not null,
   PRUEFUNG_ID INT8,
   LIST_INDEX INT4,
   primary key (KLASSENRAUM_ID)
)
create table t_dozierende_aufsichten (
   DOZIERENDE_ID INT8 not null,
   AUFSICHT_ID INT8 not null,
   LIST_INDEX INT4 not null,
   primary key (AUFSICHT_ID, LIST_INDEX)
)
create table t_anmeldungen (
   ID integer not null,
   ANMELDUNG_DATUM TIMESTAMP,
   student INT8,
   ANMELDUNG_ID INT8,
   LIST_INDEX INT4,
   primary key (ID)
)
create table t_aufsichten (
   AUFSICHT_ID integer not null,
   PRUEFUNG_ID INT8,
   LIST_INDEX INT4,
   primary key (AUFSICHT_ID)
)
create table t_studierende (
   STUDIERENDE_ID INT8 not null,
   primary key (STUDIERENDE_ID)
)
create table t_reservierungen (
   RESERVIERUNG_ID integer not null,
   VON TIMESTAMP,
   BIS TIMESTAMP,
   LIST_INDEX INT4,
   primary key (RESERVIERUNG_ID)
)
create table t_pruefungen (
   PRUEFUNG_ID integer not null,
   DATUM TIMESTAMP not null,
   BESCHREIBUNG varchar(256),
   primary key (PRUEFUNG_ID)
)
create table t_personen (
   PERSON_ID integer not null,
   NACHNAME varchar(32) not null,
   VORNAME varchar(32) not null,
   primary key (PERSON_ID)
)
create table t_adressen (
   ID integer not null,
   STRASSE varchar(32) not null,
   HAUSNUMMER integer,
   PLZ integer not null,
   ORT varchar(32) not null,
   TELEFON varchar(32),
   EMAIL varchar(32),
   primary key (ID)
)
alter table t_dozierende add constraint FK5A46C73CC3912989 foreign key (DOZIERENDE_ID) references t_personen
alter table t_faecher add constraint FK7A917D11E9B1835A foreign key (FACH_ID) references t_pruefungen
alter table t_dozierende_faecher add constraint FKF228FBD9C3912989 foreign key (DOZIERENDE_ID) references t_dozierende
alter table t_dozierende_faecher add constraint FKF228FBD983CC52FE foreign key (DOZENT_ID) references t_dozierende
alter table t_dozierende_faecher add constraint FKF228FBD9E9B1835A foreign key (FACH_ID) references t_faecher
alter table t_klassenraeume add constraint FKB9A613D5DD509A0 foreign key (PRUEFUNG_ID) references t_pruefungen
alter table t_dozierende_aufsichten add constraint FKF717FEF3C3912989 foreign key (DOZIERENDE_ID) references t_dozierende
alter table t_dozierende_aufsichten add constraint FKF717FEF3AF45A933 foreign key (AUFSICHT_ID) references t_aufsichten
alter table t_anmeldungen add constraint FK6FE58A2F8FFE823B foreign key (student) references t_studierende
alter table t_anmeldungen add constraint FK6FE58A2F3BCC3F29BC6B19BC foreign key (ANMELDUNG_ID) references t_pruefungen
alter table t_anmeldungen add constraint FK6FE58A2F3BCC3F29 foreign key (ANMELDUNG_ID) references t_studierende
alter table t_aufsichten add constraint FKF06D52BBAF45A933 foreign key (AUFSICHT_ID) references t_pruefungen
alter table t_aufsichten add constraint FKF06D52BBDD509A0 foreign key (PRUEFUNG_ID) references t_pruefungen
alter table t_studierende add constraint FK3EC8F0C5492C73CA foreign key (STUDIERENDE_ID) references t_personen
alter table t_reservierungen add constraint FKD39F37F5A0C5D5B9 foreign key (RESERVIERUNG_ID) references t_klassenraeume
create table hibernate_unique_key (
    next_hi INT4
)
insert into hibernate_unique_key values ( 0 )


I tried to write the Pruefung-Objects and Aufsicht-Objects into database, but it doesn't work. Here ist the stack trace:

Code:
28.07.2004 18:57:02 net.sf.hibernate.cfg.Environment <clinit>
INFO: Hibernate 2.1.4
28.07.2004 18:57:03 net.sf.hibernate.cfg.Environment <clinit>
INFO: loaded properties from resource hibernate.properties: {hibernate.connection.username=student, hibernate.connection.password=, hibernate.cglib.use_reflection_optimizer=true, hibernate.connection.pool_size=10, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.connection.url=jdbc:postgresql://127.0.0.1:5432/adressen_db, hibernate.connection.driver_class=org.postgresql.Driver}
28.07.2004 18:57:03 net.sf.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Adresse.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Adresse -> t_adressen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Person.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Person -> t_personen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindJoinedSubclass
INFO: Mapping joined-subclass: ch.fhz.hsw.hibernate.model.Dozent -> t_dozierende
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollection
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Dozent.faecherListe -> t_dozierende_faecher
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollection
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Dozent.aufsichtenListe -> t_dozierende_aufsichten
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindJoinedSubclass
INFO: Mapping joined-subclass: ch.fhz.hsw.hibernate.model.Student -> t_studierende
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Fach.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Fach -> t_faecher
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollection
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Fach.dozierendeListe -> t_dozierende_faecher
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Aufsicht.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Aufsicht -> t_aufsichten
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollection
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Aufsicht.aufsichtpersonenListe -> t_dozierende_aufsichten
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Klassenraum.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Klassenraum -> t_klassenraeume
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Anmeldung.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Anmeldung -> t_anmeldungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Pruefung.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Pruefung -> t_pruefungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Reservierung.hbm.xml
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindRootClass
INFO: Mapping class: ch.fhz.hsw.hibernate.model.Reservierung -> t_reservierungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-many association mappings
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Student.anmeldungListe -> t_anmeldungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Klassenraum.reservierungenListe -> t_reservierungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Pruefung.klassenraumListe -> t_klassenraeume
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Pruefung.aufsichtenListe -> t_aufsichten
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Pruefung.anmeldungListe -> t_anmeldungen
28.07.2004 18:57:03 net.sf.hibernate.cfg.Binder bindCollectionSecondPass
INFO: Mapping collection: ch.fhz.hsw.hibernate.model.Pruefung.faecherListe -> t_faecher
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing one-to-one association property references
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
28.07.2004 18:57:03 net.sf.hibernate.dialect.Dialect <init>
INFO: Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use outer join fetching: true
28.07.2004 18:57:03 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
28.07.2004 18:57:03 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 10
28.07.2004 18:57:03 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: org.postgresql.Driver at URL: jdbc:postgresql://localhost:5432/adressen_db
28.07.2004 18:57:03 net.sf.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=student, password=, driver-class=org.postgresql.Driver}
28.07.2004 18:57:03 net.sf.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of process level read-write cache is not recommended)
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use scrollable result sets: true
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Use JDBC3 getGeneratedKeys(): false
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: false
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
28.07.2004 18:57:03 net.sf.hibernate.cfg.SettingsFactory buildSettings
INFO: cache provider: net.sf.ehcache.hibernate.Provider
28.07.2004 18:57:03 net.sf.hibernate.cfg.Configuration configureCaches
INFO: instantiating and configuring caches
28.07.2004 18:57:03 net.sf.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
28.07.2004 18:57:04 net.sf.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: no JNDI name configured
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Batch-Anweisung Nummer 0 (insert into t_aufsichten (PRUEFUNG_ID, AUFSICHT_ID) values () wurde abgebrochen.
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: 23503
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: ERROR: insert or update on table "t_aufsichten" violates foreign key constraint "fkf06d52bbaf45a933"

28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: null
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: Batch-Anweisung Nummer 0 (insert into t_aufsichten (PRUEFUNG_ID, AUFSICHT_ID) values () wurde abgebrochen.
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNUNG: SQL Error: 0, SQLState: 23503
28.07.2004 18:57:05 net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SCHWERWIEGEND: ERROR: insert or update on table "t_aufsichten" violates foreign key constraint "fkf06d52bbaf45a933"

28.07.2004 18:57:05 net.sf.hibernate.JDBCException <init>
SCHWERWIEGEND: Could not execute JDBC batch update
Batch-Anweisung Nummer 0 (insert into t_aufsichten (PRUEFUNG_ID, AUFSICHT_ID) values () wurde abgebrochen.
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:107)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
   at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:59)
   at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
   at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:460)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at ch.fhz.hsw.hibernate.test.TestClass.main(TestClass.java:55)
28.07.2004 18:57:05 net.sf.hibernate.impl.SessionImpl execute
SCHWERWIEGEND: Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
   at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:59)
   at net.sf.hibernate.impl.BatcherImpl.prepareStatement(BatcherImpl.java:56)
   at net.sf.hibernate.impl.BatcherImpl.prepareBatchStatement(BatcherImpl.java:109)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:460)
   at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:442)
   at net.sf.hibernate.impl.ScheduledInsertion.execute(ScheduledInsertion.java:29)
   at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2414)
   at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
   at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
   at ch.fhz.hsw.hibernate.test.TestClass.main(TestClass.java:55)
Caused by: Batch-Anweisung Nummer 0 (insert into t_aufsichten (PRUEFUNG_ID, AUFSICHT_ID) values () wurde abgebrochen.
   at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:107)
   at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
   at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
   ... 11 more
net.sf.hibernate.JDBCException: Could not execute JDBC batch update


The classes Pruefung and Aufsicht are as follow (the schort version, without methods):

The Aufsicht-Class:
Code:
public class Aufsicht
{
    private Long aufsichtId;
    private Collection aufsichtpersonenListe;
    public Pruefung pruefung;

     // ... and so on ...
}


The Pruefung-Class:
Code:
public class Pruefung
{
    private Long pruefungId;
    private GregorianCalendar datum;
    private Collection klassenraumListe;
    private Collection aufsichtenListe;
    private Collection anmeldungListe;
    private Collection faecherListe;
    private String beschreibung;

    // ... and so on ...
}


In the Class with the method main I have following code:
Code:
public class HibernateTest
{
    private static final int SIZE = 10;
   
    private static Adresse[] adrArr;
    private static Student[] stdArr;
    private static Dozent[] dozArr;
    private static Fach[] fachArr;
    private static Pruefung[] prfArr;
    private static Anmeldung[] anmArr;
    private static Aufsicht[] aufArr;
    private static Klassenraum[] klsArr;

    static
    {
        adrArr = new Adresse[SIZE];
        stdArr = new Student[SIZE];
        dozArr = new Dozent[SIZE];
        fachArr = new Fach[SIZE];
        prfArr = new Pruefung[SIZE];
        anmArr = new Anmeldung[SIZE];
        aufArr = new Aufsicht[SIZE];
        klsArr = new Klassenraum[SIZE];
    }

    private static Session session;
    public static void main(String[] args)
    {
        try
        {
            session = HibernateUtil.currentSession();
            Transaction transaktion = session.beginTransaction();
           
            initAdressen();
            initFaecher();
            initStudierende();
            initDozierende();
            initKlassenraeume();
            initAnmeldungen();   
            initAufsichten();
            initPruefungen();
           
            transaktion.commit();
        }
        catch (HibernateException e)
        {
            System.err.println(e);
           
        } 
    }

    private static void initAdressen()
    {
       

            adrArr[0] = new Adresse("Pilatusstrasse", 12, 6002, "Luzern",
                    "041 320 00 44", "rolf@tic.ch");
            adrArr[1] = new Adresse("Bundesstrasse", 22, 6002, "Luzern",
                    "041 320 33 44", "dani@dplanet.ch");
            adrArr[2] = new Adresse("Allmendstrasse", 47, 6048, "Horw",
                    "041 340 63 11", "ursf@tic.ch");
            adrArr[3] = new Adresse("Waldheimstrasse", 18, 6010, "Kriens",
                    "041 320 06 88", "oski@tic.ch");
            adrArr[4] = new Adresse("Waldheimstrasse", 18, 6010, "Kriens",
                    "041 320 06 88", "roli@yahoo.com");
            adrArr[5] = new Adresse("Amlehnstrasse", 50, 6010, "Kriens",
                    "041 320 12 33", "dani@roche.com");

            try
            {
                // speichern
                session.save(adrArr[0]);
                session.save(adrArr[1]);
                session.save(adrArr[2]);
                session.save(adrArr[3]);
                session.save(adrArr[4]);
                session.save(adrArr[5]);
            }
            catch (HibernateException e)
            {
                System.err.println(e);
               
            }
    }

    private static void initFaecher()
    {
        try
        {
            fachArr[0] = new Fach("Informationssystementwicklung");
            fachArr[1] = new Fach("Kommunikation und Netzwerke");
            fachArr[2] = new Fach("Grundlagen der Informatik");
            fachArr[3] = new Fach("Vollkswirtschaft");
            fachArr[4] = new Fach("Betriebswiertschaftlehre");
            fachArr[5] = new Fach("Mathematik");

            // speichern
            session.save(fachArr[0]);
            session.save(fachArr[1]);
            session.save(fachArr[2]);
            session.save(fachArr[3]);
            session.save(fachArr[4]);
            session.save(fachArr[4]);
        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }

    private static void initStudierende()
    {
        try
        {

            stdArr[0] = new Student(adrArr[0], "Aregger", "Andre", 200101,
                    "FHW", 4);
            stdArr[1] = new Student(adrArr[1], "Bucheli", "Nicole", 200117,
                    "FHW", 4);
            stdArr[2] = new Student(adrArr[1], "Sigrist", "Beat", 200113,
                    "FHW", 4);
            stdArr[3] = new Student(adrArr[1], "Harmann", "Pascal", 200111,
                    "FHW", 4);
            stdArr[4] = new Student(adrArr[2], "Mattli", "Roger", 200110,
                    "FHW", 4);

            // speichern
            session.save(stdArr[0]);
            session.save(stdArr[1]);
            session.save(stdArr[2]);
            session.save(stdArr[3]);
            session.save(stdArr[4]);

        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }

    private static void initDozierende()
    {
        try
        {
            dozArr[0] = new Dozent(adrArr[3], "Bucher", "Roland");
            dozArr[1] = new Dozent(adrArr[4], "Mueller", "Daniel");
            dozArr[2] = new Dozent(adrArr[5], "Zopp", "Michael");
            dozArr[3] = new Dozent(adrArr[6], "Fischer", "Marcel");

            // speichern
            session.save(dozArr[0]);
            session.save(dozArr[1]);
            session.save(dozArr[2]);
            session.save(dozArr[3]);
        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }
   
    private static void initKlassenraeume()
    {
        try
        {
            klsArr[0] = new Klassenraum("4.02", 20);
            klsArr[1] = new Klassenraum("3.18", 24);
            klsArr[2] = new Klassenraum("3.12", 15);
            klsArr[3] = new Klassenraum("2.22", 25);
            klsArr[4] = new Klassenraum("1.02", 22);

            // speichern
            session.save(klsArr[0]);
            session.save(klsArr[1]);
            session.save(klsArr[2]);
            session.save(klsArr[3]);
            session.save(klsArr[4]);
        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }
   
    private static void initAnmeldungen()
    {
        try
        {
            anmArr[0] = new Anmeldung(new GregorianCalendar(2004, 4, 1), stdArr[0]);
            anmArr[1] = new Anmeldung(new GregorianCalendar(2004, 4, 3), stdArr[0]);
            anmArr[2] = new Anmeldung(new GregorianCalendar(2004, 4, 7), stdArr[1]);
            anmArr[3] = new Anmeldung(new GregorianCalendar(2004, 5, 2), stdArr[1]);
            anmArr[4] = new Anmeldung(new GregorianCalendar(2004, 5, 4), stdArr[1]);
            anmArr[5] = new Anmeldung(new GregorianCalendar(2004, 5, 9), stdArr[2]);
            anmArr[6] = new Anmeldung(new GregorianCalendar(2004, 5, 11), stdArr[3]);
            anmArr[7] = new Anmeldung(new GregorianCalendar(2004, 6, 19), stdArr[4]);
            anmArr[8] = new Anmeldung(new GregorianCalendar(2004, 6, 22), stdArr[4]);
            anmArr[9] = new Anmeldung(new GregorianCalendar(2004, 6, 30), stdArr[4]);

            // speichern
            session.save(anmArr[0]);
            session.save(anmArr[1]);
            session.save(anmArr[2]);
            session.save(anmArr[3]);
            session.save(anmArr[4]);
            session.save(anmArr[5]);
            session.save(anmArr[6]);
            session.save(anmArr[7]);
            session.save(anmArr[8]);
            session.save(anmArr[9]);
        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }
   
    private static void initAufsichten()
    {
        try
        {
            aufArr[0] = new Aufsicht();
            aufArr[0].addAufsichtPerson(dozArr[0]);
            aufArr[0].addAufsichtPerson(dozArr[1]);
           
            aufArr[1] = new Aufsicht();
            aufArr[1].addAufsichtPerson(dozArr[1]);
            aufArr[1].addAufsichtPerson(dozArr[2]);
           
            aufArr[2] = new Aufsicht();
            aufArr[2].addAufsichtPerson(dozArr[0]);
            aufArr[2].addAufsichtPerson(dozArr[3]);
           
            aufArr[3] = new Aufsicht();
            aufArr[3].addAufsichtPerson(dozArr[3]);
            aufArr[3].addAufsichtPerson(dozArr[1]);
           
           
            // speichern
            session.save(aufArr[0]);
            session.save(aufArr[1]);
            session.save(aufArr[2]);
            session.save(aufArr[3]);

        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }
   
    private static void initPruefungen()
    {
        try
        {
            prfArr[0] = new Pruefung();
            // Anmeldungen
            prfArr[0].addAnmeldung(anmArr[0]);
            prfArr[0].addAnmeldung(anmArr[1]);
            prfArr[0].addAnmeldung(anmArr[2]);
            // Aufsicht
            prfArr[0].addAufsicht(aufArr[0]);
            // Fach (nur ein)
            prfArr[0].addFach(fachArr[0]);
            // Klassenraum (nur ein)
            prfArr[0].addKlassenraum(klsArr[0]);
            // Datum
            prfArr[0].setDatum(new GregorianCalendar(2004, 7, 23));
            // Beschreibung
            prfArr[0].setBeschreibung("Alle Unterlagen erlaubt");
           
            // Aufsicht-Objekt bervollstaendigen
            aufArr[0].setPruefung(prfArr[0]);
           
            // speichern
            session.save(prfArr[0]);

        }
        catch (HibernateException e)
        {
            System.err.println(e);
        }
    }
}


I don't see, if something is wrong with the database or in my code. Doe's anybody see, what is wrong in my example?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.