-->
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.  [ 5 posts ] 
Author Message
 Post subject: Problem with assigned id.
PostPosted: Sat Nov 13, 2004 10:34 am 
Beginner
Beginner

Joined: Mon Sep 08, 2003 10:56 am
Posts: 35
This is sort of "half a problem" I have an object with assigned id. When I create the object and give it an assigned ID, and save the object It throws the stacktrace below *BUT* everything get's saved in the database as I intended. So it's working, I'd just like to stop the error from happening.

Hibernate version:2.1.5

Mapping documents:

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>
    <class
        name="com.skulls.hibernate.legacy.dbosalehouse.OpenHouse"
        table="open_house"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="openId"
            column="openId"
            type="java.lang.Long"
        >
            <generator class="assigned">
            </generator>
        </id>

        <property
            name="pls"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="pls"
            length="11"
            not-null="true"
        />

        <property
            name="startTime"
            type="java.sql.Time"
            update="true"
            insert="true"
            access="property"
            column="startTime"
            length="8"
            not-null="true"
        />

        <property
            name="endTime"
            type="java.sql.Time"
            update="true"
            insert="true"
            access="property"
            column="endTime"
            length="8"
            not-null="true"
        />

        <property
            name="day"
            type="java.sql.Date"
            update="true"
            insert="true"
            access="property"
            column="day"
            length="10"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-OpenHouse.xml
            containing the additional properties and place it in your merge dir.
        -->

    </class>

</hibernate-mapping>



Code between sessionFactory.openSession() and session.close():
Code:
com.skulls.hibernate.legacy.dbosalehouse.OpenHouse hse = new com.skulls.hibernate.legacy.dbosalehouse.OpenHouse();
hse.setOpenId(new Long(h.getId().intValue()));
hse.setPls(h.getProperty());
hse.setDay(new java.sql.Date(h.getStartTime().getTime()));
hse.setStartTime(new java.sql.Time(h.getStartTime().getTime()));
hse.setEndTime(new java.sql.Time(h.getEndTime().getTime()));
UserTransaction tx = null;
try {
   InitialContext ctx = new InitialContext();
       tx = (UserTransaction) ctx.lookup(TX_NAME);
   tx.begin();
   Session sess = HibernateContext.getSession(DBO_SALEHOUSE);

   sess.save( hse );
} catch (HibernateException e) {
   //handle error
}

Full stack trace of any exception that occurs:
Code:
08:16:00,234 INFO  [STDOUT] net.sf.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.directbyowner.hibernate.legacy.dbosalehouse.OpenHouse
   at net.sf.hibernate.id.Assigned.generate(Assigned.java:26)
   at net.sf.hibernate.impl.SessionImpl.saveWithGeneratedIdentifier(SessionImpl.java:765)
   at net.sf.hibernate.impl.SessionImpl.save(SessionImpl.java:738)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1387)

Name and version of the database you are using:
MySQL 3.2.x
The generated SQL (show_sql=true):

Code:
08:16:00,296 INFO  [STDOUT] Hibernate: insert into open_house (pls, startTime, endTime, day, openId) values (?, ?, ?, ?, ?)


Debug level Hibernate log excerpt: DEBUG


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 3:41 am 
Newbie

Joined: Fri Aug 29, 2003 4:36 am
Posts: 16
Location: Belgium
Code:
08:16:00,234 [b]INFO[/b]  [STDOUT] net.sf.hibernate.id.IdentifierGenerationException:


the "exception" is logged with severity INFO, which indicate it is not a problem but merely some useful information.

Bart.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 15, 2004 6:08 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Quote:
Name and version of the database you are using:
MySQL 3.2.x


Are you using ISAM tables? They don't support transactioning.

HTH
Ernst


Top
 Profile  
 
 Post subject: INFO exceptions howto detect
PostPosted: Fri Jul 15, 2005 3:14 pm 
Beginner
Beginner

Joined: Wed Jun 01, 2005 6:51 pm
Posts: 27
Location: Philippines
How do you detect in a HibernateException that its severity is INFO?

I suppose I have to put the session.save() in its own try catch block from the commit and close blocks, right?

_________________
Mike "Ollie" Oliver


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 15, 2005 5:12 pm 
Senior
Senior

Joined: Sun Jan 04, 2004 2:46 pm
Posts: 147
The code that throws this exception checks the assigned ids are not equal to null (unset). Is it possible you haven't assigned the id properly?


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

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.