I am running hibente from within cocoon and postgresql. The above error message section, [test.User#63], increments by 1 everytime I refresh the browser, i.e a call is made to the table, a key(sequence) is obtained but nothing is written to the database. Can anybody tell me what I am not doing correctly?
My code s so:
1. persist class (snippet) - User.class
public User(){
}
public int getID() {
return userID;
}
public void setID(int newUserID) {
this.userID = newUserID;
}
public String getUserName() {
return (userName);
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return (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;
}
2. main class (snippet)
public void add(){
try {
Configuration cfg = new Configuration()
.configure ();
SessionFactory sf = cfg.buildSessionFactory();
Session session = sf.openSession();
Transaction transaction = session.beginTransaction();
User usr = new User();
usr.setID(1);
usr.setUserName("postgres");
usr.setPassword("postgres");
usr.setEmailAddress("
[email protected]");
usr.setLastLogon(newDate);
session.save(usr);
//session.flush();
transaction.commit();
}
catch (Exception e) {
System.out.println("Exception in Hibernate:" + e.getMessage());
}
3. hibernate.cfg.xml (snippet)
<property name="connection.driver">org.postgresql.Driver</property>
<property name="connection.url">jdbc:postgresql://localhost:5432/mydb</property>
<property name="connection.username">usr</property>
<property name="connection.password">pwd</property>
<property name="connection.pool_size">5</property>
<property name="jdbc.batch_size">0</property>
<property name="jdbc.use_scrollable_resultsets">true</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"/>
4 User2.hbm.xml (snippet)
<hibernate-mapping package="test">
<class name="User" table="users">
<id name="ID" type="integer" column="LogonID" unsaved-value="null">
<generator class="sequence">
<param name="sequence">seq_id_mytable</param>
</generator>
</id>
<property name="userName" column="Name" />
<property name="password" column="Password" />
<property name="emailAddress" column="EmailAddress" />
<property name="lastLogon" column="Lastlogon" />
</class>
</hibernate-mapping>