hi people,
i need help using hibernate. it's rather a newbie question. i'm using postgresql 7.3.2 on linux with jdk1.4.2 and org.postgresql.Driver class. i'm trying to insert a simple object with no associations, one assigned pk of type Long. although i see correct insert sql stmt in hibernate logs, no real rows are written into the db.
my persistent object:
Code:
public class Location {
private Long fId;
private int fParent;
private String fName;
public Location() {
}
/**
* @hibernate.property
*/
public int getParent() {
return fParent;
}
public void setParent(int pParent) {
this.fParent = pParent;
}
/**
* @hibernate.id column="location_id"
* unsaved-value="null"
* generator-class="native"
*/
public Long getId() {
return fId;
}
public void setId(Long id) {
this.fId = id;
}
/**
* @hibernate.property
*/
public String getName() {
return fName;
}
public void setName(String name) {
this.fName = name;
}
}
my mapping file:
Code:
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="domain.transmission.hardware.Location"
table="location"
>
<id
name="id"
column="location_id"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native">
</generator>
</id>
<property
name="parent"
type="int"
column="parent"
/>
<property
name="name"
type="java.lang.String"
column="name"
/>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Location.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
my test code:
Code:
try {
Configuration cfg = new Configuration().addClass(Location.class);
SessionFactory sf = cfg.buildSessionFactory();
// new SchemaExport(cfg).create(true, true);
Session sess = sf.openSession();
Location l = new Location();
l.setId(new Long(1));
l.setParent(0);
l.setName("Izmir");
Serializable serializable = sess.save(l);
System.out.println("serializable = " + serializable);
// l=new Location();
// sess.load(l,new Integer(1));
// System.out.println("l.getName() = " + l.getName());
sess.flush();
sess.close();
} catch (HibernateException e) {
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}