-->
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.  [ 6 posts ] 
Author Message
 Post subject: Hibernate not persisting anything
PostPosted: Wed Aug 27, 2003 5:32 pm 
Newbie

Joined: Wed Aug 27, 2003 5:12 pm
Posts: 3
hi,

please tell me why the heck hibernate is not persisting anything but "acts" like it is working correctly

here is the deal:

Code:
User user = new User();

user.setLogin(login);
user.setPassword(password);

Session session = sf.openSession();
   
session.save(user);
session.flush();

session.close();


this works like it should. no exceptions AND the user.id (integer using generator="sequence" gets increased [even on the database]) BUT nothing ever makes it into the db .. show_sql shows:

Code:
Hibernate: select nextval ('uid_sequence')
Hibernate: insert into users (login, password, id) values (?, ?, ?)


my connection on the sql server says (SELECT COUNT(*) FROM users) == 0

one thing a query for the just "persisted" object works .. eg.

Code:
session.find("from User as user where user.login = ?", login, Hibernate.STRING);


finds that objects UNTIL i restart the server. then everything is like before .. so i have a nice memory only persister .. w00t.

so i thought its because of a transaction .. oh wait i havent registered/configured any BUT my sql server (PostgreSQL) shows "idle in transaction". i run a standalone application .. no app server whatsoever. heres my config:

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 2.0//EN"

"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">

<hibernate-configuration>
    <session-factory>

        <property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
        <property name="hibernate.connection.url">jdbc:postgresql://super.duper.host.com/db</property>
        <property name="hibernate.connection.username">omfg</property>
        <property name="hibernate.connection.password">secret</property>

        <!-- properties -->
        <property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
        <property name="show_sql">true</property>

        <!-- mapping files -->
        <mapping resource="mapping/User.hbm.xml"/>
    </session-factory>

</hibernate-configuration>


please someone tell me how to configure hibernate so that i get:

    no pooling
    no transactions
    no caching
    nothing else BUT a simple persister that does what it should?


thanks.

i'm just 1 step away from writing hand crafted plain old jdbc again.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 5:39 pm 
Beginner
Beginner

Joined: Wed Aug 27, 2003 8:55 am
Posts: 28
Location: Dallas, TX
Have you tried turning logging to debug? This is usually the first step.


Top
 Profile  
 
 Post subject: no
PostPosted: Wed Aug 27, 2003 5:56 pm 
Newbie

Joined: Wed Aug 27, 2003 5:12 pm
Posts: 3
no since everything "acts" like its working .. as i said everything works but nothing ever gets persisted.

but anyways i tried wrapping the whole stuff into a

Quote:
...
Transaction tx = session.beginTransaction();

session.save(...);

tx.commit();
...


and that did the trick. seems like hibernate2 forces u to use transactions. well actually it isnt that bad when i think about it since transactions generally are a good thing.

anyways when not configuring anything hibernate should assume we are not using it. but maybe my driver defaults to autoCommit=false. oh well nothing is easy when using 3rd party software. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 6:08 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
THis is like FAQ number 1 or 2!!!!


Please read the FAQ it is there for a reason.


You must commit() a JDBC transaction somehow, either by using the Transaction API, or by committing the JDBC connection manually.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 6:10 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
P.S. You should never use autocommit true. It is always a Bad Thing.


I'm AMAZED at how many people misunderstand this!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 27, 2003 6:21 pm 
Newbie

Joined: Wed Aug 27, 2003 5:12 pm
Posts: 3
ok ok, i got it.

i know its a bad thing to use autocommit .. but its just a test application for hibernate nothing i would ever use in the real world. ;)


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