Hi,
I have an issue with saving data to a postgresql database via hibernate, for which I get the above mentioned exception. Can anybody shine any light on this issue please?
1. Table schema.
CREATE TABLE "users" (
"Name" character varying(40),
"Password" character varying(20),
"EmailAddress" character varying(40),
"Lastlogon" date,
"logonID" integer NOT NULL DEFAULT nextval('seq_id_mytable'::text),
CONSTRAINT "users_pkey" PRIMARY KEY ("logonID")
) WITH OIDS;
2. hibernate.cfg.xml (snippet)
<session-factory>
<property name="connection.driver_class">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/test</property>
<property name="connection.username">x</property>
<property name="connection.password">x</property>
<property name="jdbc.batch_size">0</property>
<property name="jdbc.use_scrollable_resultsets">false</property>
<property name="show_sql">true</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.PostgreSQLDialect</property>
<mapping resource="test/User2.hbm.xml"/>
</session-factory>
3. User2.hbm.xml file (snippet)
<class name="test.User" table="users">
<id name="ID" type="integer" column="LogonID">
<generator class="sequence">
<param name="sequence">seq_id_mytable</param>
</generator>
</id>
<property name="userName" column="Name" type="string"/>
<property name="password" column="Password" type="string"/>
<property name="emailAddress" column="EmailAddress" type="string"/>
<property name="lastLogon" column="Lastlogon" type="date"/>
</class>
4. User.class (snippet)
private Integer userID;
private String userName;
private String password;
private String emailAddress;
private Date lastLogon;
public User(){
}
public Integer getID() {
return userID;
}
public void setID(Integer newUserID) {
this.userID = newUserID;
}
public String getUserName() {
return (userName == null ? "" : userName);
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return (password == null ? "" : password);
}
public void setPassword(String password) {
this.password = password;
}
public String getEmailAddress() {
return emailAddress;
}
public void setEmailAddress(String emailAddress) {
this.emailAddress = emailAddress;
}
public Date getLastLogon() {
return lastLogon;
}
public void setLastLogon(Date newLastLogon) {
this.lastLogon = newLastLogon;
}
5. The action class (snippet)
Configuration cfg = new Configuration()
.configure ();
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction transaction = session.beginTransaction();
User usr = new User();
usr.setUserName("postgres");
usr.setPassword("postgres");
usr.setEmailAddress("test@hotmail.coml");
usr.setLastLogon(newDate);
session.save(usr);
//session.flush();
transaction.commit();
Andrew
|