-->
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.  [ 2 posts ] 
Author Message
 Post subject: Exception in Hibernate: could not insert: [test.User#32]
PostPosted: Thu Jan 22, 2004 9:03 am 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 9:54 am 
Regular
Regular

Joined: Mon Nov 24, 2003 6:36 pm
Posts: 105
can you show us the full stack trace?
(add log4j if you want to see all of hibernates output)

Mapping file, and action code look okay...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.