-->
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: Mapping to a List index issue
PostPosted: Thu Jul 01, 2004 1:01 pm 
Newbie

Joined: Thu Jul 01, 2004 12:47 pm
Posts: 1
We have a complext database and everything seems to be working fine except we have two tables, a Promotion Table and a AcademicProgram Table. We want the Promotion Table to map to a list of Academic programs storing the list index into the Academic program as program_order. We set this up as you can see in the mapping doc below and it is returning an error because it is tring to enter null into program_order. We had a many to many relationshp with a rel table with this functionality working but now we are doing a one to many and it doesn't seem to allow us to have the list take care of the index inserts. If anyone has had any luck with this any information would be greatly appreciated.

Hibernate version: 2.1.4
Mapping Documents

Code:
[code]<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="com.classesusa.beans.Promotion"
    table="PROMOTIONS"
><cache usage="read-write" />

    <id
        name="promotionId"
        type="java.lang.Integer"
        column="PROMOTION_ID"
    >
        <generator class="native" />
    </id>

    <property
        name="promotionName"
        type="java.lang.String"
        column="PROMOTION_NAME"
        not-null="true"
        unique="true"
        length="60"
    />
    <property
        name="updateTs"
        type="java.sql.Timestamp"
        column="UPDATE_TS"
        not-null="true"
        length="23"
    />
    <property
        name="createTs"
        type="java.sql.Timestamp"
        column="CREATE_TS"
        not-null="true"
        length="23"
    />
    <property
        name="promotionShortname"
        type="java.lang.String"
        column="PROMOTION_SHORTNAME"
        unique="true"
        length="30"
    />
    <property
        name="promotionSummary"
        type="java.lang.String"
        column="PROMOTION_SUMMARY"
        length="2000"
    />

    <property
        name="transmissionInterval"
        type="java.lang.Integer"
        column="TRANSMISSION_INTERVAL"
        length="10"
    />
    <property
        name="transmissionStartDatetime"
        type="java.sql.Timestamp"
        column="TRANSMISSION_START_DATETIME"
        length="23"
    />
    <property
        name="leadCap"
        type="java.lang.Integer"
        column="LEAD_CAP"
        length="10"
    />
    <property
        name="thruDate"
        type="java.sql.Timestamp"
        column="THRU_DATE"
        length="23"
    />
    <property
        name="fromDate"
        type="java.sql.Timestamp"
        column="FROM_DATE"
        not-null="true"
        length="23"
    />

    <!-- associations -->
    <!-- bi-directional one-to-many association to PromoLeadRat -->
    <set
        name="promoLeadRats"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="PROMOTION_ID" />
        </key>
        <one-to-many
            class="com.classesusa.beans.PromoLeadRat"
        />
    </set>
    <!-- bi-directional one-to-many association to PromotionException -->
    <set
        name="promotionExceptions"
        lazy="true"
        inverse="true"
    >
        <key>
            <column name="PROMOTION_ID" />
        </key>
        <one-to-many
            class="com.classesusa.beans.PromotionException"
        />
    </set>

    <!-- bi-directional one-to-many association to FormFieldFilter -->
    <set
        name="filters"
        lazy="false"
        inverse="true"
    ><cache usage="read-write" />
        <key>
            <column name="PROMOTION_ID" />
        </key>
        <one-to-many
            class="com.classesusa.beans.Filter"
        />
    </set>

    <!-- bi-directional one-to-many association to Lead -->
   
    <!-- bi-directional many-to-one association to Client -->
    <many-to-one
        name="client"
        class="com.classesusa.beans.Client"
        not-null="true"
    >
        <column name="CLIENT_ID" />
    </many-to-one>
    <!-- bi-directional many-to-one association to TransmissionFrequency -->
    <many-to-one
        name="transmissionFrequency"
        class="com.classesusa.beans.TransmissionFrequency"
        not-null="true"
    >
        <column name="TRANSMISSION_FREQUENCY_ID" />
    </many-to-one>
   <!-- associations -->
    <!-- bi-directional one-to-many association to TransmissionProtocol -->
    <set
        name="transmissionProtocols"
        lazy="false"
        inverse="true"
    ><cache usage="read-write" />
        <key>
            <column name="PROMOTION_ID" />
        </key>
        <one-to-many
            class="com.classesusa.beans.TransmissionProtocol"
        />
    </set>
    <!-- bi-directional one-to-many association to AcademicProgram -->
    <list
        name="academicPrograms"
        lazy="false"
        cascade="all"
    >
        <key>
            <column name="PROMOTION_ID" />
        </key>
        <index column="PROGRAM_ORDER"/>
        <one-to-many
            class="com.classesusa.beans.AcademicProgram"
        />
    </list>


</class>
</hibernate-mapping>[/code]
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
    "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
   
<hibernate-mapping>
<!--
    Created by the Middlegen Hibernate plugin

    http://boss.bekk.no/boss/middlegen/
    http://hibernate.sourceforge.net/
-->

<class
    name="com.classesusa.beans.AcademicProgram"
    table="ACADEMIC_PROGRAMS"
><cache usage="read-write" />

    <id
        name="academicProgramId"
        type="java.lang.Integer"
        column="ACADEMIC_PROGRAM_ID"
    >
        <generator class="native" />
    </id>

    <property
        name="programName"
        type="java.lang.String"
        column="PROGRAM_NAME"
        not-null="true"
        unique="true"
        length="100"
    />
    <property
        name="programDesc"
        type="java.lang.String"
        column="PROGRAM_DESC"
        length="2000"
    />

    <!-- associations -->
    <!-- bi-directional many-to-one association to Promotion -->
    <many-to-one
        name="promotion"
        class="com.classesusa.beans.Promotion"
        not-null="true"
    >
        <column name="PROMOTION_ID" />
    </many-to-one>
    <!-- bi-directional many-to-one association to StatusItem -->
    <many-to-one
        name="statusItem"
        class="com.classesusa.beans.StatusItem"
        not-null="true"
    >
        <column name="STATUS_ID" />
    </many-to-one>
   
</class>
</hibernate-mapping>


Strack Trace:
org.springframework.jdbc.UncategorizedSQLException: (HibernateAccessor): encountered SQLException [Cannot insert the value NULL into column 'PROGRAM_ORDER', table 'ClassesUSA.dbo.ACADEMIC_PROGRAMS'; column does not allow nulls. INSERT fails.]; nested exception is java.sql.SQLException: Cannot insert the value NULL into column 'PROGRAM_ORDER', table 'ClassesUSA.dbo.ACADEMIC_PROGRAMS'; column does not allow nulls. INSERT fails.
java.sql.SQLException: Cannot insert the value NULL into column 'PROGRAM_ORDER', table 'ClassesUSA.dbo.ACADEMIC_PROGRAMS'; column does not allow nulls. INSERT fails.
at net.sourceforge.jtds.jdbc.SqlMessage.toSQLException(SqlMessage.java:85)
at net.sourceforge.jtds.jdbc.SQLWarningChain.addOrReturn(SQLWarningChain.java:99)
at net.sourceforge.jtds.jdbc.Tds.goToNextResult(Tds.java:837)
at net.sourceforge.jtds.jdbc.TdsStatement.getMoreResults(TdsStatement.java:707)
at net.sourceforge.jtds.jdbc.TdsStatement.executeCallImpl(TdsStatement.java:301)
at net.sourceforge.jtds.jdbc.TdsStatement.internalExecuteCall(TdsStatement.java:281)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.execute(PreparedStatement_base.java:133)
at net.sourceforge.jtds.jdbc.PreparedStatement_base.executeUpdate(PreparedStatement_base.java:286)
at org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:233)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:528)
at net.sf.hibernate.persister.EntityPersister.insert(EntityPersister.java:432)
at net.sf.hibernate.impl.ScheduledIdentityInsertion.execute(ScheduledIdentityInsertion.java:29)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:932)
at net.sf.hibernate.impl.SessionImpl.doSave(SessionImpl.java:857)
at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:775)
at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1387)
at net.sf.hibernate.engine.Cascades$4.cascade(Cascades.java:114)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:436)
at net.sf.hibernate.engine.Cascades.cascadeCollection(Cascades.java:526)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:452)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:503)
at net.sf.hibernate.engine.Cascades.cascade(Cascades.java:482)
at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1474)
at net.sf.hibernate.impl.SessionImpl.update(SessionImpl.java:1354)
at org.springframework.orm.hibernate.HibernateTemplate$12.doInHibernate(HibernateTemplate.java:276)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.update(HibernateTemplate.java:274)
at com.classesusa.dao.hibernate.HibernatePromotionDAO.updatePromotion(HibernatePromotionDAO.java:115)
at com.classesusa.dao.hibernate.HibernateAcademicProgramDAOTest.testFindByIdSaveUpdateDeleteAcademicProgram(HibernateAcademicProgramDAOTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at junit.framework.TestCase.runTest(TestCase.java:166)
at junit.framework.TestCase.runBare(TestCase.java:140)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:131)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:421)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:305)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:186)

Database Info:
We are using Microsoft SQL 2000 for our database.

Code:
Java Code:
   public void updatePromotion(Promotion promotion) {
      getHibernateTemplate().update(promotion);
      
   }


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.