-->
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.  [ 2 posts ] 
Author Message
 Post subject: hilo increments but no new record
PostPosted: Sat Apr 02, 2005 4:01 pm 
Newbie

Joined: Sat Apr 02, 2005 2:36 pm
Posts: 4
Location: Philadelphia
Hey,
I am using the hilo generator. When I ask the service layer to add an item the hilo counter gets incremented, however there is no new record.

I guess I'm thrown by the fact that there is no exception. I was getting good at resolving those :) Thanks for any pointers,
Amir

Hibernate version: 2

Mapping documents: Submission.hbm.xml:
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="org.mathforum.pow.model.Submission" table="amir" >
        <id name="submissionId" column="amir_id" type="java.lang.Long" unsaved-value="0">
            <generator class="hilo">
                <param name="table">hibernate_unique_key</param>
                <param name="column">next_hi</param>
                <param name="max_lo">1</param>
            </generator>
        </id>
        <property name="shortSolution" column="amir_text1" type="java.lang.String" />
        <property name="longSolution" column="amir_text2" type="java.lang.String" />
    </class>
</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
Code:
        try {
            System.err.println("DEBUG ADT: SubmissionId: " + Submission.getSubmissionId());
            System.err.println("DEBUG ADT: short: " + Submission.getShortSolution());
            System.err.println("DEBUG ADT: long: " + Submission.getLongSolution());
            session.save(Submission);
            session.flush();
        } catch (HibernateException he) {
            System.err.println("DEBUG ADT: Hibernate exception: " + he.getMessage() + he);
            log.error("Hibernate exception: " + he.getMessage());
            throw new RuntimeException(he);
        } finally {
            if (session != null) {
                try {
                    session.close();
                } catch (HibernateException he) {
                    log.error("Hibernate exception: " + he.getMessage());
                    throw new RuntimeException(he);
                }
            }
            log.debug("leaving Submission.addSubmission");
        }


Full stack trace of any exception that occurs: no exceptions

Name and version of the database you are using: postgres 7.3

The generated SQL (show_sql=true): Hibernate: insert into amir (amir_text1, amir_text2, amir_id) values (?, ?, ?)

Debug level Hibernate log excerpt: (how do I get hibernate to log at a debug level?) other debug output:
Quote:
DEBUG ADT: entering Submission.addSubmission
Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@10e6cbd [ connectionPool
DataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@1f60430 [ acquireIncremen
t -> 1, autoCommitOnClose -> false, connectionTesterClassName -> com.mchange.v2.c3p0.impl.D
efaultConnectionTester, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions ->
false, idleConnectionTestPeriod -> 0, initialPoolSize -> 2, maxIdleTime -> 5000, maxPoolSiz
e -> 100, maxStatements -> 100, minPoolSize -> 2, nestedDataSource -> com.mchange.v2.c3p0.D
riverManagerDataSource@52c6f [ description -> null, driverClass -> null, factoryClassLocati
on -> null, jdbcUrl -> jdbc:postgresql://xxxx.xxxxx.org:5432/xxxxx, properties -> {user
=xxxxx, password=xxxxx} ] , propertyCycle -> 300, testConnectionOnCheckout -> false ] , f
actoryClassLocation -> null, numHelperThreads -> 3 ]
DEBUG ADT: SubmissionId: null
DEBUG ADT: short: hard coded string
DEBUG ADT: long: hard coded string
Hibernate: insert into amir (amir_text1, amir_text2, amir_id) values (?, ?, ?)



the sql for the table is:
Code:
CREATE TABLE amir
(
  amir_id int8 NOT NULL,
  amir_text1 varchar(50) NOT NULL,
  amir_text2 varchar(50) NOT NULL
)
WITH OIDS;
ALTER TABLE amir OWNER TO amir;


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 9:39 am 
Newbie

Joined: Sat Apr 02, 2005 2:36 pm
Posts: 4
Location: Philadelphia
In case any other newbies make this mistake the solution is to use transactions, so the code around save should be:

Code:
            Transaction transaction = session.beginTransaction();
            session.save(Submission);
            transaction.commit();


-Amir


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.