-->
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: object not reaching database
PostPosted: Mon May 02, 2005 7:09 pm 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
I have a problem persisting a simple object. Jugding by the console output it seems fine but no changes to db are being made.
Here are the files

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>
        <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property>
        <property name="hibernate.connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
        <property name="hibernate.connection.url">jdbc:microsoft:sqlserver://localhost;DataBaseName=Proba;User=Boris;Password=Boris</property>
        <property name="hibernate.connection.username">Boris</property>
        <property name="hibernate.connection.password">Boris</property>
       
        <property name="show_sql">true</property>
        <property name="transaction.factory_class">
             org.hibernate.transaction.JDBCTransactionFactory
        </property>
        <property name="hibernate.cache.provider_class">
             org.hibernate.cache.HashtableCacheProvider
        </property>
        <property name="hibernate.hbm2ddl.auto">update</property>
        <mapping resource="Student.hbm.xml"/>
    </session-factory>
</hibernate-configuration>


Student.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="Student" table="Studenti">
                <id name="id" column="brojIndeksa" type="long">
                     
                </id>
                <property name="ime" column="Ime" type="java.lang.String" not-null="true"/>
                <property name="prezime" column="Prezime" type="java.lang.String" not-null="true"/>
               
        </class>
</hibernate-mapping>


relevant code

Code:
SessionFactory sf = new Configuration().configure().buildSessionFactory();
      Session sesija = sf.openSession();
      Student student;
      Student s = new Student(new Long(1000),"Marvin","Monroe");
      Transaction tx = sesija.beginTransaction();
           
      try
      {
         tx = sesija.beginTransaction();
         sesija.persist(s);
         tx.commit();
      }
      catch (HibernateException e)
      {
         e.printStackTrace();
      }
      finally {sesija.flush();}
     
      student = (Student)sesija.load(Student.class,new Long(1000));
      System.out.print(student.toString());
      sesija.close();
      sf.close();


and the console output

Code:
May 3, 2005 12:48:49 AM org.hibernate.cfg.Environment <clinit>
INFO: Hibernate 3.0.1
May 3, 2005 12:48:49 AM org.hibernate.cfg.Environment <clinit>
INFO: hibernate.properties not found
May 3, 2005 12:48:49 AM org.hibernate.cfg.Environment <clinit>
INFO: using CGLIB reflection optimizer
May 3, 2005 12:48:49 AM org.hibernate.cfg.Environment <clinit>
INFO: using JDK 1.4 java.sql.Timestamp handling
May 3, 2005 12:48:49 AM org.hibernate.cfg.Configuration configure
INFO: configuring from resource: /hibernate.cfg.xml
May 3, 2005 12:48:49 AM org.hibernate.cfg.Configuration getConfigurationInputStream
INFO: Configuration resource: /hibernate.cfg.xml
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration addResource
INFO: Mapping resource: Student.hbm.xml
May 3, 2005 12:48:50 AM org.hibernate.cfg.HbmBinder bindRootPersistentClassCommonValues
INFO: Mapping class: Student -> Studenti
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration doConfigure
INFO: Configured SessionFactory: null
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
May 3, 2005 12:48:50 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
May 3, 2005 12:48:50 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default batch fetch size: 1
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Generate SQL with comments: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Order SQL updates by primary key: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory createQueryTranslatorFactory
INFO: Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
May 3, 2005 12:48:50 AM org.hibernate.hql.ast.ASTQueryTranslatorFactory <init>
INFO: Using ASTQueryTranslatorFactory
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query language substitutions: {}
May 3, 2005 12:48:50 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 3, 2005 12:48:50 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
May 3, 2005 12:48:50 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
May 3, 2005 12:48:50 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://localhost;DataBaseName=Proba;User=Boris;Password=Boris
May 3, 2005 12:48:50 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=Boris, password=****}
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Scrollable result sets: enabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: JDBC3 getGeneratedKeys(): disabled
May 3, 2005 12:48:50 AM org.hibernate.transaction.TransactionFactoryFactory buildTransactionFactory
INFO: Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory
May 3, 2005 12:48:50 AM org.hibernate.transaction.TransactionManagerLookupFactory getTransactionManagerLookup
INFO: No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic flush during beforeCompletion(): disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Automatic session close at end of transaction: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Second-level cache: enabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Query cache: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory createCacheProvider
INFO: Cache provider: org.hibernate.cache.HashtableCacheProvider
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Optimize cache for minimal puts: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Structured second-level cache entries: enabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Echoing all SQL to stdout
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Statistics: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Deleted entity synthetic identifier rollback: disabled
May 3, 2005 12:48:50 AM org.hibernate.cfg.SettingsFactory buildSettings
INFO: Default entity-mode: pojo
May 3, 2005 12:48:51 AM org.hibernate.impl.SessionFactoryImpl <init>
INFO: building session factory
May 3, 2005 12:48:51 AM org.hibernate.impl.SessionFactoryObjectFactory addInstance
INFO: Not binding factory to JNDI, no JNDI name configured
May 3, 2005 12:48:51 AM org.hibernate.dialect.Dialect <init>
INFO: Using dialect: org.hibernate.dialect.SQLServerDialect
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Using Hibernate built-in connection pool (not for production use!)
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: Hibernate connection pool size: 20
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: autocommit mode: false
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: using driver: com.microsoft.jdbc.sqlserver.SQLServerDriver at URL: jdbc:microsoft:sqlserver://localhost;DataBaseName=Proba;User=Boris;Password=Boris
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider configure
INFO: connection properties: {user=Boris, password=****}
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: Running hbm2ddl schema update
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: fetching database metadata
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: updating schema
May 3, 2005 12:48:51 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing extends queue
May 3, 2005 12:48:51 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing collection mappings
May 3, 2005 12:48:51 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing association property references
May 3, 2005 12:48:51 AM org.hibernate.cfg.Configuration secondPassCompile
INFO: processing foreign key constraints
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: table found: Proba.dbo.Studenti
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: columns: [brojindeksa, ime, prezime]
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: foreign keys: []
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.TableMetadata <init>
INFO: indexes: [pk_student]
May 3, 2005 12:48:51 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
INFO: schema update complete
May 3, 2005 12:48:51 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:microsoft:sqlserver://localhost;DataBaseName=Proba;User=Boris;Password=Boris
May 3, 2005 12:48:51 AM org.hibernate.impl.SessionFactoryImpl checkNamedQueries
INFO: Checking 0 named queries
Hibernate: select student0_.brojIndeksa as brojInde1_0_, student0_.Ime as Ime0_0_, student0_.Prezime as Prezime0_0_ from Studenti student0_ where student0_.brojIndeksa=?
9088 Boris Jockov
Hibernate: insert into Studenti (Ime, Prezime, brojIndeksa) values (?, ?, ?)
1000 Marvin Monroe
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: SQL Warning: 0, SQLState:
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Database changed to Proba
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: SQL Warning: 0, SQLState:
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed database context to 'Proba'.
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: SQL Warning: 0, SQLState:
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: [Microsoft][SQLServer 2000 Driver for JDBC]Language changed to us_english
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: SQL Warning: 0, SQLState:
May 3, 2005 12:49:18 AM org.hibernate.util.JDBCExceptionReporter logWarnings
WARNING: [Microsoft][SQLServer 2000 Driver for JDBC][SQLServer]Changed language setting to us_english.
May 3, 2005 12:49:23 AM org.hibernate.impl.SessionFactoryImpl close
INFO: closing
May 3, 2005 12:49:23 AM org.hibernate.connection.DriverManagerConnectionProvider close
INFO: cleaning up connection pool: jdbc:microsoft:sqlserver://localhost;DataBaseName=Proba;User=Boris;Password=Boris



im using ms sql server 2000 and ms jdbc driver. Loading objects from db works fine but saving them does not.
What am i missing?
thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 8:22 am 
Beginner
Beginner

Joined: Mon Apr 11, 2005 8:37 am
Posts: 22
hibernate.cfg.xml looks ok so far...

Have to tried to explicitly stating:

<id ... >
<generator class="assigned" />
</id>

in your student.hbm.xml ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 10:20 am 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
I tried it and the results are identical. The funny thing is when I try to insert an object that already exists hibernate reports violation of primary constraint which is off course good. But the same code without that object in db still doesn't work all the way


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 8:43 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
You transaction code is broken - mutiple start Tx, unecessary fluch after the commit...bad. Two things: (1) Try using jTDS jdbc driver (2) Use the following as a guide to correct TX management.

Code:
Session sess = factory.openSession();
Transaction tx;
try {
     tx = sess.beginTransaction();
     //do some work
     ...
     tx.commit();
}
catch (Exception e) {
     if (tx!=null) tx.rollback();
     throw e;
}
finally {
     sess.close();
}


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 03, 2005 9:45 pm 
Beginner
Beginner

Joined: Mon May 02, 2005 6:17 pm
Posts: 41
thanks david. your second suggestion worked. the code i have posted was just a test code. multiple transaction start was of course a mistake. thank s again!


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.