Hello;
i have a table that contains thrree columns
reviewId | reviewerName |reviewerId
whare reviewId is primary key and auto_increment.
i had POJO class
Code:
package com.ahs.da.hib;
/**
* Review entity.
*
* @author MyEclipse Persistence Tools
*/
public class Review implements java.io.Serializable {
// Fields
private Integer reviewId;
private String reviewName;
private String reviewerId;
// Constructors
/** default constructor */
public Review() {
}
/** full constructor */
public Review(Integer reviewId, String reviewName, String reviewerId) {
this.reviewId = reviewId;
this.reviewName = reviewName;
this.reviewerId = reviewerId;
}
// Property accessors
public Integer getReviewId() {
return this.reviewId;
}
public void setReviewId(Integer reviewId) {
this.reviewId = reviewId;
}
public String getReviewName() {
return this.reviewName;
}
public void setReviewName(String reviewName) {
this.reviewName = reviewName;
}
public String getReviewerId() {
return this.reviewerId;
}
public void setReviewerId(String reviewerId) {
this.reviewerId = reviewerId;
}
}
i have to insert a row into that review table
i am trying to set the reviewerName, reviewerId and saveing the session trying to commit the transaction. it is failing to insert row into table.
mapping file is
Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!--
Mapping file autogenerated by MyEclipse Persistence Tools
-->
<hibernate-mapping>
<class name="com.ahs.da.hib.Review" table="review" catalog="review">
<id name="reviewId" type="java.lang.Integer">
<column name="reviewId" />
<generator class="assigned" />
</id>
<property name="reviewName" type="java.lang.String">
<column name="reviewName" length="45" not-null="true" />
</property>
<property name="reviewerId" type="java.lang.String">
<column name="reviewerId" length="45" not-null="true" />
</property>
</class>
</hibernate-mapping>
Data access code is
Code:
org.hibernate.Session hsession=com.ahs.da.hib.MySQLSF.getSession();
Transaction tx=hsession.beginTransaction();
try{
com.ahs.da.hib.Review review =new com.ahs.da.hib.Review();
review.setReviewName(reviewer);
review.setReviewerId(reviewer);
hsession.save(review);
tx.commit();
}catch(Exception e){
tx.rollback();
return mapping.findForward("failure");
}
what i confused is is there any special way to handle the auto incremented columns. how can i insert the row int to table
thanks in advance