-->
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: hibernate won't persist my classes!!
PostPosted: Fri Jul 14, 2006 9:09 am 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:20 pm
Posts: 20
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3

Mapping documents:<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping
>
<class
name="store.Orders"
table="orders"
>

<id
name="orderId"
column="orderId"
type="long"
>
<generator class="native">
<!--
To add non XDoclet generator parameters, create a file named
hibernate-generator-params-Orders.xml
containing the additional parameters and place it in your merge dir.
-->
</generator>
</id>

<property
name="name"
type="java.lang.String"
update="true"
insert="true"
column="name"
/>

<property
name="price"
type="double"
update="true"
insert="true"
column="price"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Orders.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>

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

Orders o=(Orders)s.get(Orders.class,new Long(1));
System.out.println(o.getName());
o.setName("new Name");
o.setPrice(999);
s.saveOrUpdate(o);

s.flush();

Full stack trace of any exception that occurs: no exacption

Name and version of the database you are using: mySql 4

The generated SQL (show_sql=true):update orders set name=?, price=? where orderId=?

hi. i'm trying to change an object, but for some reasons the changes won't reflect in the database.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 14, 2006 10:37 am 
Newbie

Joined: Sun Jan 29, 2006 9:27 pm
Posts: 10
Hello

I think you have to open commit a transaction, please, somebody correct me if I'm wrong.

Code:
s.beginTransaction();

// I don't get this one, are you trying to load Orders with Id 1?
// If so, it's not the way I use to, I use the load method
Orders o=(Orders)s.get(Orders.class,new Long(1));

System.out.println(o.getName());
o.setName("new Name");
o.setPrice(999);
s.saveOrUpdate(o);

// You don't need this here
// s.flush();

s.getTransaction().commit();


Regards, Demián.
[/code]


Top
 Profile  
 
 Post subject: yea i just figured that out..
PostPosted: Fri Jul 14, 2006 12:04 pm 
Beginner
Beginner

Joined: Mon Mar 27, 2006 5:20 pm
Posts: 20
but do i have to?


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.