-->
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.  [ 3 posts ] 
Author Message
 Post subject: Exception in Hibernate: could not insert: [test.User#63]
PostPosted: Thu Jan 22, 2004 6:40 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
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("test@hotmail.com");
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>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 22, 2004 6:41 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Please do not crosspost the forums. Answers please to http://forum.hibernate.org/viewtopic.php?t=927306


Top
 Profile  
 
 Post subject: appologies for any trouble caused...
PostPosted: Thu Jan 22, 2004 6:43 pm 
Regular
Regular

Joined: Mon Jan 19, 2004 10:39 pm
Posts: 84
Location: Nottingham, England
gloeglm wrote:
Please do not crosspost the forums. Answers please to http://forum.hibernate.org/viewtopic.php?t=927306


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