-craig
import net.sf.hibernate.HibernateException; import net.sf.hibernate.Session; import net.sf.hibernate.SessionFactory; import net.sf.hibernate.cfg.Configuration;
import java.util.List;
/**
* @hibernate.class
*/
public class Foo { private long id;
private String bar; public Foo() {
} public Foo(String bar) {
this.bar = bar;
} /**
* @hibernate.id
* generator-class="increment"
*/
public long getId() {
return id;
} public void setId(long id) {
this.id = id;
} /**
* @hibernate.property
*/
public String getBar() {
return bar;
} public void setBar(String bar) {
this.bar = bar;
} public String toString() {
return this.bar;
}private static SessionFactory sessionFactory;
public static void main(String[] args) {
try {
Foo.sessionFactory = new Configuration().addClass(Foo.class).buildSessionFactory();
Session readSession = Foo.sessionFactory.openSession();
createFoo();
// I would now expect to see "FooBar", and I do
readSession.flush(); // Extra flush just for the heck of it
System.out.println("Queried " + readSession.createCriteria(Foo.class).list().get(0));
readSession.flush(); // Extra flush just for the heck of it
updateFoo();
// I would now expect to see "Modified", but it is still "FooBar"
readSession.flush(); // Extra flush just for the heck of it
System.out.println("Queried " + readSession.createCriteria(Foo.class).list().get(0));
readSession.flush(); // Extra flush just for the heck of it
deleteFoo();
} catch (HibernateException e) {
e.printStackTrace();
}
} private static void createFoo() throws HibernateException {
Session session = Foo.sessionFactory.openSession();
Foo foo = new Foo("FooBar");
System.out.println("Creating " + foo);
session.save(foo);
session.flush();
session.close();
} private static void updateFoo() throws HibernateException {
Session session = Foo.sessionFactory.openSession();
Foo foo = (Foo) session.createCriteria(Foo.class).list().get(0);
foo.setBar("Modified");
System.out.println("Modifying to " + foo);
session.update(foo);
session.flush();
session.close();
} private static void deleteFoo() throws HibernateException {
Session session = Foo.sessionFactory.openSession();
List foos = session.createCriteria(Foo.class).list();
for (int i = 0; i < foos.size(); i++) {
Foo foo = (Foo) foos.get(i);
System.out.println("Deleting " + foo);
session.delete(foo);
}
session.flush();
session.close();
}}
------------------------------------------------------- This SF.Net email sponsored by: Free pre-built ASP.NET sites including Data Reports, E-commerce, Portals, and Forums are available now. Download today and enter to win an XBOX or Visual Studio .NET. http://aspnet.click-url.com/go/psa00100003ave/direct;at.aspnet_072303_01/01 _______________________________________________ hibernate-devel mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/hibernate-devel
