Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / June 2005

Tip: Looking for answers? Try searching our database.

Hibernate -- what does this exception mean??

Thread view: 
amatijaca@gmail.com - 23 Jun 2005 17:15 GMT
Hi there,

I am a relative newbie to Hibernate, and I have managed so far to
persist 2-3 tables, however, on this one table, I am having some real
difficulty.  I keep getting this exception:

net.sf.hibernate.id.IdentifierGenerationException: ids for this class
must be manually assigned before calling save():
com.cibc.gdp.tecp.envoy.audit.persistence.PostProcessResults

I had a look at IdentifierGenerationException and the explanation was
not very useful...  Below I have included the info...  I realy have no
clue what the exception is trying to tell me.  The XML looks fine, and
so does the class....

Thanks for all the help!!

Alex.

============================================

My mappings for this table look as:

    <class
name="com.cibc.gdp.tecp.envoy.audit.persistence.PostProcessResults"
table="ARCHIVE_CHEQUE">
        <id name="prior_event_id" column="EVENT_ID" />
        <property name="archive_cheque_id" column="ARCHIVE_CHEQUE_ID" />
        <property name="account_number" column="ACC_NMBR" />
        <property name="cheque_amount" column="CHEQUE_AMT" />
        <property name="transaction_code" column="TRANSACTION_CODE" />
        <property name="bank_number" column="BANK_NMBR" />
        <property name="transit_number" column="TRANSIT_NMBR" />
    </class>

The class PostProcessResults looks like this:

package com.cibc.gdp.tecp.envoy.audit.persistence;

/**
* Date Jun 22, 2005
*
* @author AM509
*/
public class PostProcessResults {
    int account_number; //
    int cheque_amount; //
    int transaction_code; //
    int bank_number; //
    int transit_number; //
    String prior_event_id; //
    String archive_cheque_id; //
    /**
    * @return Returns the account_number.
    */
    public int getAccount_number() {
        return account_number;
    }
    /**
    * @param account_number The account_number to set.
    */
    public void setAccount_number(int account_number) {
        this.account_number = account_number;
    }
    /**
    * @return Returns the archive_cheque_id.
    */
    public String getArchive_cheque_id() {
        return archive_cheque_id;
    }
    /**
    * @param archive_cheque_id The archive_cheque_id to set.
    */
    public void setArchive_cheque_id(String archive_cheque_id) {
        this.archive_cheque_id = archive_cheque_id;
    }
    /**
    * @return Returns the bank_number.
    */
    public int getBank_number() {
        return bank_number;
    }
    /**
    * @param bank_number The bank_number to set.
    */
    public void setBank_number(int bank_number) {
        this.bank_number = bank_number;
    }
    /**
    * @return Returns the cheque_amount.
    */
    public int getCheque_amount() {
        return cheque_amount;
    }
    /**
    * @param cheque_amount The cheque_amount to set.
    */
    public void setCheque_amount(int cheque_amount) {
        this.cheque_amount = cheque_amount;
    }
    /**
    * @return Returns the prior_event_id.
    */
    public String getPrior_event_id() {
        return prior_event_id;
    }
    /**
    * @param prior_event_id The prior_event_id to set.
    */
    public void setPrior_event_id(String prior_event_id) {
        this.prior_event_id = prior_event_id;
    }
    /**
    * @return Returns the transaction_code.
    */
    public int getTransaction_code() {
        return transaction_code;
    }
    /**
    * @param transaction_code The transaction_code to set.
    */
    public void setTransaction_code(int transaction_code) {
        this.transaction_code = transaction_code;
    }
    /**
    * @return Returns the transit_number.
    */
    public int getTransit_number() {
        return transit_number;
    }
    /**
    * @param transit_number The transit_number to set.
    */
    public void setTransit_number(int transit_number) {
        this.transit_number = transit_number;
    }

}

And the persistence looks like this:

            PostProcessAudit ppa = (PostProcessAudit) event;
            ppa.prepareForPersistence();
//            EverythingForPersistence eftp = new EverythingForPersistence();
//            eftp.populatePostProcessAudit(ppa);

            PostProcessResults ppr = new PostProcessResults();
            ppr.setAccount_number(Integer.parseInt(ppa.getAccount_number()));
            ppr.setArchive_cheque_id(ppa.getArchive_cheque_id());
            ppr.setBank_number(Integer.parseInt(ppa.getBank_number()));
//            ppr.setChannelId(ppa.getChannelId());
            ppr.setCheque_amount(Integer.parseInt(ppa.getCheque_amount()));
//            ppr.setCurrency_code(Integer.parseInt(ppa.getCurrency_code()));
            ppr.setPrior_event_id(ppr.getPrior_event_id());
            ppr.setTransaction_code(Integer.parseInt(ppa.getTransaction_code()));
            ppr.setTransit_number(Integer.parseInt(ppa.getTransit_number()));

            Session session =
HibernateUtil.getInstance(factory).currentSession();

            Transaction tx = null;
            tx = session.beginTransaction();
            session.save(ppr);
            tx.commit();
            HibernateUtil.closeSession();
Georg J. Stach - 23 Jun 2005 17:32 GMT
Hi,

> net.sf.hibernate.id.IdentifierGenerationException: ids for this class
> must be manually assigned before calling save():
> com.cibc.gdp.tecp.envoy.audit.persistence.PostProcessResults

I didn't get this error so far, but I could imagine that you

a) have to tell Hibernate of which type your column is (eg.
java.lang.Integer)

b) have so set a generator for the ID (eg. a sequence, native, HiLo
algorithm ...)

--
Bye
Georg
amatijaca@gmail.com - 23 Jun 2005 18:37 GMT
Hello Georg,

thanks for the reply!  I am definitely specifying in my XML the column
types -- all values in my XML have specific table names.  I am not
using any generator, because I am specifying the fields myself.

I just realized that my table ARCHIVE_CHEQUE is a table with a compound
key -- two String fields.  Perhaps my XML is not correct, I am
specifying only on <id /> field, since I have a compound key, perhaps I
should be specifying my IDs for both fields.

Do you have any idea how to specify a compound key in the hibernate
mapping xml??

Thanks, Alex.
amatijaca@gmail.com - 23 Jun 2005 20:34 GMT
Problem solved!!

It was the 'composite key' issue!  The following clippet of XML fixed
the problem:

    <class
name="com.cibc.gdp.tecp.envoy.audit.persistence.PostProcessResults"
table="ARCHIVE_CHEQUE">
        <composite-id>
            <key-property name="prior_event_id" column="EVENT_ID"/>
            <key-property name="archive_cheque_id" column="ARCHIVE_CHEQUE_ID"/>
        </composite-id>
        <property name="account_number" column="ACC_NMBR" />
        <property name="cheque_amount" column="CHEQUE_AMT" />
        <property name="transaction_code" column="TRANSACTION_CODE" />
        <property name="bank_number" column="BANK_NMBR" />
        <property name="transit_number" column="TRANSIT_NMBR" />
    </class>

Thanks to everyone who replied!

Cheers, Alex.
Georg J. Stach - 24 Jun 2005 19:28 GMT
I didn't gather good experiences with composite keys.
In fact, it is also not recommended (by Chr. King and G. Bauer) using them.
You'll see that there are quite a number of points you have to consider
when using composite-keys, e.g. when saving a new column.
Searching in the hibernate-documentation (or better having a look in
"Hibernate in action") will show you that you should use an additional
"version" column for identifying the newly inserted columns, or to use
_one_ column with primary key relation.

Bye,
Georg

> Problem solved!!
>
[quoted text clipped - 18 lines]
>
> Cheers, Alex.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.