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.  [ 4 posts ] 
Author Message
 Post subject: session.save problem
PostPosted: Fri Apr 07, 2006 9:39 am 
Beginner
Beginner

Joined: Mon Feb 13, 2006 8:34 pm
Posts: 27
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.0

I use MySQL 5.0. When I try to save some example object to database I have sth like this

Quote:
Hibernate: insert into Sample (nr, description) values (?, ?)


and of course no row is added to appropriate table. What can be the reason of this. This is my class:

Code:

/**
* @hibernate.class table = "Sample"
*          
*/

public class Sample {

   private Long id;
   private int nr;
   private String description;

   public Sample() {
      super();
      // TODO Auto-generated constructor stub
   }

   public Sample(int nr, String description) {
      super();
      // TODO Auto-generated constructor stub
      this.nr = nr;
      this.description = description;
   }
   
   /**
    *  @hibernate.id column = "sample_id"
    *             generator-class = "identity"
    */
   
   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   /**
    * @hibernate.property column = "nr"
    * not-null="false"
    */
   
   public int getNr() {
      return nr;
   }

   public void setNr(int nr) {
      this.nr = nr;
   }

   /**
    * @hibernate.property column = "description"
    * not-null="false"
    * length="100"
    */

   public String getDescription() {
      return description;
   }

   public void setDescription(String description) {
      this.description = description;
   }
}


and this is my cfg file:
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.connection.username">root</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/hibernate</property>
<property name="dialect">org.hibernate.dialect.MySQLInnoDBDialect</property>
<property name="hibernate.connection.password">admin</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</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>
<!--  configuration pool via c3p0
-->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">100</property>
<!--  seconds
-->
<property name="c3p0.max_size">50</property>
<property name="c3p0.max_statements">0</property>
<property name="c3p0.min_size">4</property>
<property name="c3p0.timeout">100</property>
<!--  seconds
-->
<!--  DEPRECATED very expensive property name="c3p0.validate>
-->
<mapping resource="mapping\simple_inheritance\Osoba.hbm.xml"/>
<mapping resource="mapping\simple_inheritance\Sample.hbm.xml"/>
</session-factory>
</hibernate-configuration>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 07, 2006 9:54 am 
Pro
Pro

Joined: Mon Jan 24, 2005 5:39 am
Posts: 216
Location: Germany
Can you post the code between session.beginTransaction()
and commit ?

_________________
dont forget to rate !


Top
 Profile  
 
 Post subject: Code
PostPosted: Fri Apr 07, 2006 12:49 pm 
Beginner
Beginner

Joined: Mon Feb 13, 2006 8:34 pm
Posts: 27
steckemetz wrote:
Can you post the code between session.beginTransaction()
and commit ?


This is exacly what I do:

Code:
Sample s = new Sample(1,"blabla");
      Transaction t = null;
      try{
         
         Configuration cfg = new Configuration().configure();
         sessionFactory = cfg.buildSessionFactory();
         session = sessionFactory.openSession();
         
         t = session.beginTransaction();
         session.save(s);
         t.commit();
      }
      catch(Exception e)
      {   
         e.printStackTrace();
      }
      finally
      {
         session.close();
         sessionFactory.close();
      }


Top
 Profile  
 
 Post subject: Business Help
PostPosted: Fri Apr 07, 2006 2:43 pm 
Newbie

Joined: Tue Apr 04, 2006 10:46 pm
Posts: 1
I am newbie and asking for advice. I applied as recruiter manager at JobQueen, they promise to pay $87,000.00/year. I would like to know how can I get quality sales reps in China. So if you want to help me out please contact me direct at my email: kimwongshu@yahoo.com


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