-->
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.  [ 3 posts ] 
Author Message
 Post subject: persistence of objects in postgresql 8.0.2
PostPosted: Wed Jun 22, 2005 6:11 am 
Newbie

Joined: Wed Jun 22, 2005 5:25 am
Posts: 6
i'm having problems with keeping my objects persistent. i thought it had something to do with cascades or my mapping files. therefore i tried out the cat-example in the hibernate manual. this gave me the same problem. if i read an object from the database, then change some variable of the object and then flush the hibernate session, hibernate seems to recognize the object is dirty and tries to persist it. but i dont see any changes in my database table...

Hibernate version:
hibernate 3.0.5

Mapping documents:

Cat.hbm.xml:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
   <class name="dbdemo.Cat" table="cat">
      <!-- A 32 hex character is our surrogate key. It's automatically
      generated by Hibernate with the UUID pattern. -->
      <id name="id" type="string" unsaved-value="null" >
         <column name="cat_id" sql-type="char(32)" not-null="true"/>
         <generator class="uuid.hex"/>
      </id>
      
      <!-- A cat has to have a name, but it shouldn' be too long. -->
      <property name="name">
         <column name="name" length="16" not-null="true"/>
      </property>
      <property name="sex"/>
      <property name="weight"/>
   </class>
</hibernate-mapping>


hibernate.cfg.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
      "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
      "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory name="java:hibernate/SessionFactory">
        <property name="hibernate.connection.username">postgres</property>
        <property name="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</property>
        <property name="hibernate.connection.url">jdbc:postgresql://kaijuu.cs.kuleuven.ac.be:5432/rockanango</property>
        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
       
      <mapping resource="dbdemo/Cat.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Code between sessionFactory.openSession() and session.close():

Code:
public static void main(String[] args)
    {
        Session session = currentSession();
        Transaction tx = session.beginTransaction();

        Cat tarzan = new Cat();
        tarzan.setName("Tarzan");
        tarzan.setSex('M');
        tarzan.setWeight(10.4f);

        session.save(tarzan);

        tx.commit();
        System.out.println(tarzan);
        tarzan.setName("Jane");
        tarzan.setSex('F');
        System.out.println(tarzan);
        session.flush();
       
        closeSession();
    }


Name and version of the database you are using:
PostgreSQL 8.0.2

Debug level Hibernate log excerpt:

11:55:20,538 DEBUG SessionFactoryImpl:262 - instantiated session factory
11:55:20,538 INFO SessionFactoryImpl:379 - Checking 0 named queries
11:55:20,569 DEBUG SessionImpl:250 - opened session at timestamp: 4585202157723648
11:55:20,585 DEBUG JDBCTransaction:46 - begin
11:55:20,585 DEBUG ConnectionManager:296 - opening JDBC connection
11:55:20,585 DEBUG DriverManagerConnectionProvider:93 - total checked-out connections: 0
11:55:20,585 DEBUG DriverManagerConnectionProvider:99 - using pooled JDBC connection, pool size: 0
11:55:20,585 DEBUG JDBCTransaction:50 - current autocommit status: false
11:55:20,585 DEBUG DefaultSaveOrUpdateEventListener:159 - saving transient instance
11:55:20,585 DEBUG AbstractSaveEventListener:100 - generated identifier: 06baa79d04a3791a0104a3791d890001, using strategy: org.hibernate.id.UUIDHexGenerator
11:55:20,585 DEBUG AbstractSaveEventListener:133 - saving [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,600 DEBUG JDBCTransaction:83 - commit
11:55:20,600 DEBUG SessionImpl:323 - automatically flushing session
11:55:20,600 DEBUG AbstractFlushingEventListener:52 - flushing session
11:55:20,600 DEBUG AbstractFlushingEventListener:102 - processing flush-time cascades
11:55:20,600 DEBUG AbstractFlushingEventListener:150 - dirty checking collections
11:55:20,600 DEBUG AbstractFlushingEventListener:167 - Flushing entities and processing referenced collections
11:55:20,616 DEBUG AbstractFlushingEventListener:203 - Processing unreferenced collections
11:55:20,616 DEBUG AbstractFlushingEventListener:217 - Scheduling collection removes/(re)creates/updates
11:55:20,616 DEBUG AbstractFlushingEventListener:79 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
11:55:20,616 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
11:55:20,616 DEBUG Printer:83 - listing entities:
11:55:20,616 DEBUG Printer:90 - dbdemo.Cat{sex=M, name=Tarzan, weight=10.4, id=06baa79d04a3791a0104a3791d890001}
11:55:20,616 DEBUG AbstractFlushingEventListener:267 - executing flush
11:55:20,616 DEBUG BasicEntityPersister:1825 - Inserting entity: [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,632 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:55:20,632 DEBUG SQL:324 - insert into cat (name, sex, weight, cat_id) values (?, ?, ?, ?)
11:55:20,632 DEBUG AbstractBatcher:378 - preparing statement
11:55:20,632 DEBUG BasicEntityPersister:1612 - Dehydrating entity: [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,632 DEBUG AbstractBatcher:27 - Adding to batch
11:55:20,632 DEBUG AbstractBatcher:54 - Executing batch size: 1
11:55:20,647 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:55:20,647 DEBUG AbstractBatcher:416 - closing statement
11:55:20,647 DEBUG AbstractFlushingEventListener:294 - post flush
11:55:20,647 DEBUG JDBCContext:278 - before transaction completion
11:55:20,647 DEBUG SessionImpl:372 - before transaction completion
11:55:20,647 DEBUG JDBCTransaction:96 - committed JDBC Connection
11:55:20,647 DEBUG JDBCContext:283 - after transaction completion
11:55:20,647 DEBUG SessionImpl:403 - after transaction completion
cat: Tarzan, sex: M, weight: 10.4
cat: Jane, sex: F, weight: 10.4
11:55:20,663 DEBUG AbstractFlushingEventListener:52 - flushing session
11:55:20,663 DEBUG AbstractFlushingEventListener:102 - processing flush-time cascades
11:55:20,663 DEBUG AbstractFlushingEventListener:150 - dirty checking collections
11:55:20,663 DEBUG AbstractFlushingEventListener:167 - Flushing entities and processing referenced collections
11:55:20,663 DEBUG BasicEntityPersister:2595 - dbdemo.Cat.name is dirty
11:55:20,663 DEBUG BasicEntityPersister:2595 - dbdemo.Cat.sex is dirty
11:55:20,663 DEBUG DefaultFlushEntityEventListener:121 - Updating entity: [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,663 DEBUG AbstractFlushingEventListener:203 - Processing unreferenced collections
11:55:20,663 DEBUG AbstractFlushingEventListener:217 - Scheduling collection removes/(re)creates/updates
11:55:20,663 DEBUG AbstractFlushingEventListener:79 - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
11:55:20,663 DEBUG AbstractFlushingEventListener:85 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
11:55:20,678 DEBUG Printer:83 - listing entities:
11:55:20,678 DEBUG Printer:90 - dbdemo.Cat{sex=F, name=Jane, weight=10.4, id=06baa79d04a3791a0104a3791d890001}
11:55:20,678 DEBUG AbstractFlushingEventListener:267 - executing flush
11:55:20,678 DEBUG BasicEntityPersister:1940 - Updating entity: [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,678 DEBUG AbstractBatcher:290 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
11:55:20,678 DEBUG SQL:324 - update cat set name=?, sex=?, weight=? where cat_id=?
11:55:20,678 DEBUG AbstractBatcher:378 - preparing statement
11:55:20,678 DEBUG BasicEntityPersister:1612 - Dehydrating entity: [dbdemo.Cat#06baa79d04a3791a0104a3791d890001]
11:55:20,678 DEBUG AbstractBatcher:27 - Adding to batch
11:55:20,678 DEBUG AbstractBatcher:54 - Executing batch size: 1
11:55:20,694 DEBUG AbstractBatcher:298 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
11:55:20,694 DEBUG AbstractBatcher:416 - closing statement
11:55:20,694 DEBUG AbstractFlushingEventListener:294 - post flush
11:55:20,694 DEBUG SessionImpl:269 - closing session
11:55:20,694 DEBUG ConnectionManager:317 - closing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
11:55:20,694 DEBUG DriverManagerConnectionProvider:129 - returning connection to pool, pool size: 1
11:55:20,694 DEBUG JDBCContext:283 - after transaction completion
11:55:20,694 DEBUG SessionImpl:403 - after transaction completion


between 11:55:20,647 and 11:55:20,663 the cat gets printed and the sex and name of the cat gets changed and also printed. then it seems hibernate tries to put these changes in the database. to me everything seems to go fine in the logs, but nothing happens in the database...

i am really stuck...
what is going wrong / am i doing wrong?
can it be at a lower level then hibernate (for example the jdbc driver, i use the one from postgresql, postgresql-8.1dev-400.jdbc3.jar)?

thanks alot!
[/b]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 9:04 am 
Newbie

Joined: Tue May 17, 2005 4:54 am
Posts: 15
Location: Germany, Karlsruhe
What do you expect else, if you commit the transaction right before having done those changes?

API says to flush() : "Force the Session to flush. Must be called at the end of a unit of work, before commiting the transaction and closing the session (Transaction.commit() calls this method). Flushing is the process of synchronising the underlying persistent store with persistable state held in memory."

Georg


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 22, 2005 10:09 am 
Newbie

Joined: Wed Jun 22, 2005 5:25 am
Posts: 6
isn't the Cat-object, tarzan, supposed to be persistent after i saved it in the transaction?

i mean: after i save tarzan in the db and change something on the object it won't change in the database? at least that's what i understood from the following link from the docs: http://www.hibernate.org/hib_docs/v3/reference/en/html_single/#objectstate-modifying

or do you always have to create a transaction and commit it to change a value in an object?


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