Hi,
Still waiting fior reply. In the meantime i want to clear onething that the problem is not specifically related to the use of popup (or lookup). Even if i use combo box with showing the service type name on front and at the backend having its value as it primary key the problem also came. I went through my copy of "Hibernate in Action" and in chapter i found a paragraph mentioning hibernate working on this and it appears from there that hibernate checks the value of primary key for not null and also if it found version number than checks its as well so there the root of problem ( i am not saying that hibernate is doing anything wrong there u ppl are best at ORM and i know that it is a difficult topic and hats off to u r great work).Can u suggest any alternative here or how would u handle the situation with say combobox or lookup (specially the lookup as my main page dont fetch all the service types). One of the solution struck to my mind was to make an inetrceptor and then seeing that if primary key is set than the object is not transient. Is this a good thing to do and any alternatives u ppl can suggest.
For u r refernce these rae my objects and mappings (using annotations)
Code:
package com.inov8.iserv.common.model;
import java.util.*;
import javax.persistence.*;
import org.apache.commons.lang.builder.*;
import com.inov8.iserv.common.model.framework.*;
import com.inov8.iserv.common.model.*;
import javax.persistence.*;
import com.inov8.iserv.*;
/**
* The ServiceModel entity bean.
*
* @author Shoaib Akhtar Inov8 Limited
* @version $Revision: 1.20 $, $Date: 2006/03/06 19:29:08 $
*
*
* @spring.bean name="ServiceModel"
*/
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true)
@javax.persistence.SequenceGenerator(name = "SERVICE_seq",sequenceName = "SERVICE_seq", initialValue = 0)
@Table(name = "SERVICE")
public class ServiceModel extends BasePersistableModel {
private ServiceTypeModel serviceTypeIdServiceTypeModel;
private Long serviceId;
private String name;
private Boolean active;
private String description;
private String comments;
private Date createdOn;
private Date updatedOn;
private Integer versionNo;
/**
* Default constructor.
*/
public ServiceModel() {
}
/**
* Value object constructor.
*/
public ServiceModel(ServiceModel value) {
if (value != null) {
setServiceId(value.getServiceId());
}
if (value != null) {
setServiceTypeId(value.getServiceTypeId());
}
if (value != null) {
setName(value.getName());
}
if (value != null) {
setActive(value.getActive());
}
if (value != null) {
setDescription(value.getDescription());
}
if (value != null) {
setComments(value.getComments());
}
if (value != null) {
setCreatedBy(value.getCreatedBy());
}
if (value != null) {
setUpdatedBy(value.getUpdatedBy());
}
if (value != null) {
setCreatedOn(value.getCreatedOn());
}
if (value != null) {
setUpdatedOn(value.getUpdatedOn());
}
if (value != null) {
setVersionNo(value.getVersionNo());
}
}
/**
* Return the primary key.
*
* @return Long with the primary key.
*/
@javax.persistence.Transient
public Long getPrimaryKey() {
return getServiceId();
}
/**
* Set the primary key.
*
* @param primaryKey the primary key
*/
@javax.persistence.Transient
public void setPrimaryKey(Long primaryKey) {
setServiceId(primaryKey);
}
/**
* Returns the value of the <code>serviceId</code> property.
*
*/
@Column(name = "SERVICE_ID" , nullable = false )
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SERVICE_seq")
public Long getServiceId() {
return serviceId;
}
/**
* Sets the value of the <code>serviceId</code> property.
*
* @param serviceId the value for the <code>serviceId</code> property
*
*/
public void setServiceId(Long serviceId) {
this.serviceId = serviceId;
}
/**
* Returns the value of the <code>name</code> property.
*
*/
@Column(name = "NAME" , nullable = false , length=50 )
public String getName() {
return name;
}
/**
* Sets the value of the <code>name</code> property.
*
* @param name the value for the <code>name</code> property
*
* @spring.validator type="required"
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="50"
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the value of the <code>active</code> property.
*
*/
@Column(name = "IS_ACTIVE" , nullable = false )
public Boolean getActive() {
return active;
}
/**
* Sets the value of the <code>active</code> property.
*
* @param active the value for the <code>active</code> property
*
* @spring.validator type="required"
* @spring.validator type="boolean"
*/
public void setActive(Boolean active) {
this.active = active;
}
/**
* Returns the value of the <code>description</code> property.
*
*/
@Column(name = "DESCRIPTION" , length=255 )
public String getDescription() {
return description;
}
/**
* Sets the value of the <code>description</code> property.
*
* @param description the value for the <code>description</code> property
*
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="255"
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the value of the <code>comments</code> property.
*
*/
@Column(name = "COMMENTS" , length=255 )
public String getComments() {
return comments;
}
/**
* Sets the value of the <code>comments</code> property.
*
* @param comments the value for the <code>comments</code> property
*
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="255"
*/
public void setComments(String comments) {
this.comments = comments;
}
/**
* Returns the value of the <code>createdOn</code> property.
*
*/
@Column(name = "CREATED_ON" )
public Date getCreatedOn() {
return createdOn;
}
/**
* Sets the value of the <code>createdOn</code> property.
*
* @param createdOn the value for the <code>createdOn</code> property
*
*/
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
/**
* Returns the value of the <code>updatedOn</code> property.
*
*/
@Column(name = "UPDATED_ON" )
public Date getUpdatedOn() {
return updatedOn;
}
/**
* Sets the value of the <code>updatedOn</code> property.
*
* @param updatedOn the value for the <code>updatedOn</code> property
*
*/
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
/**
* Returns the value of the <code>versionNo</code> property.
*
*/
@Version
@Column(name = "VERSION_NO" )
public Integer getVersionNo() {
return versionNo;
}
/**
* Sets the value of the <code>versionNo</code> property.
*
* @param versionNo the value for the <code>versionNo</code> property
*
*/
public void setVersionNo(Integer versionNo) {
this.versionNo = versionNo;
}
/**
* Returns the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
* @return the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
*/
@ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER)
@JoinColumn(name = "SERVICE_TYPE_ID")
public ServiceTypeModel getRelationServiceTypeIdServiceTypeModel(){
return serviceTypeIdServiceTypeModel;
}
/**
* Returns the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
* @return the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
*/
@javax.persistence.Transient
public ServiceTypeModel getServiceTypeIdServiceTypeModel(){
return getRelationServiceTypeIdServiceTypeModel();
}
/**
* Sets the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
* @param serviceTypeModel a value for <code>serviceTypeIdServiceTypeModel</code>.
*/
@javax.persistence.Transient
public void setRelationServiceTypeIdServiceTypeModel(ServiceTypeModel serviceTypeModel) {
this.serviceTypeIdServiceTypeModel = serviceTypeModel;
}
/**
* Sets the value of the <code>serviceTypeIdServiceTypeModel</code> relation property.
*
* @param serviceTypeModel a value for <code>serviceTypeIdServiceTypeModel</code>.
*/
@javax.persistence.Transient
public void setServiceTypeIdServiceTypeModel(ServiceTypeModel serviceTypeModel) {
setRelationServiceTypeIdServiceTypeModel(new ServiceTypeModel(serviceTypeModel));
}
/**
* Returns the value of the <code>serviceTypeId</code> property.
*
*/
@javax.persistence.Transient
public Long getServiceTypeId() {
if (serviceTypeIdServiceTypeModel != null) {
return serviceTypeIdServiceTypeModel.getServiceTypeId();
} else {
return null;
}
}
/**
* Sets the value of the <code>serviceTypeId</code> property.
*
* @param serviceTypeId the value for the <code>serviceTypeId</code> property
*/
@javax.persistence.Transient
public void setServiceTypeId(Long serviceTypeId) {
if (serviceTypeIdServiceTypeModel == null) {
serviceTypeIdServiceTypeModel = new ServiceTypeModel();
}
serviceTypeIdServiceTypeModel.setServiceTypeId(serviceTypeId);
}
/**
* Used by the display tag library for rendering a checkbox in the list.
* @return String with a HTML checkbox.
*/
@Transient
public String getCheckbox() {
String checkBox = "<input type=\"checkbox\" name=\"checkbox";
checkBox += "_"+ getServiceId();
checkBox += "\"/>";
return checkBox;
}
/**
* Helper method for Struts with displaytag
*/
@javax.persistence.Transient
public String getPrimaryKeyParameters() {
String parameters = "";
parameters += "&serviceId=" + getServiceId();
return parameters;
}
/**
* Helper method for default Sorting on Primary Keys
*/
@javax.persistence.Transient
public String[] getPrimaryKeysFieldName()
{
ArrayList<String> pkFieldNameList = new ArrayList<String>();
pkFieldNameList.add("serviceId");
String[] pkFieldNameArray = new String[pkFieldNameList.size()];
return (String[])pkFieldNameList.toArray(pkFieldNameArray);
}
}
and the other one is
Code:
package com.inov8.iserv.common.model;
import java.util.*;
import javax.persistence.*;
import org.apache.commons.lang.builder.*;
import com.inov8.iserv.common.model.framework.*;
import com.inov8.iserv.common.model.*;
import javax.persistence.*;
import com.inov8.iserv.*;
/**
* The ServiceTypeModel entity bean.
*
* @author Shoaib Akhtar Inov8 Limited
* @version $Revision: 1.20 $, $Date: 2006/03/06 19:29:08 $
*
*
* @spring.bean name="ServiceTypeModel"
*/
@Entity
@org.hibernate.annotations.Entity(dynamicInsert = true)
@javax.persistence.SequenceGenerator(name = "SERVICE_TYPE_seq",sequenceName = "SERVICE_TYPE_seq", initialValue = 0)
@Table(name = "SERVICE_TYPE")
public class ServiceTypeModel extends BasePersistableModel {
private Collection<ServiceModel> serviceTypeIdServiceModelList = new ArrayList<ServiceModel>();
private Long serviceTypeId;
private String name;
private Boolean active;
private String description;
private String comments;
private Date updatedOn;
private Date createdOn;
private Integer versionNo;
/**
* Default constructor.
*/
public ServiceTypeModel() {
}
/**
* Value object constructor.
*/
public ServiceTypeModel(ServiceTypeModel value) {
if (value != null) {
setServiceTypeId(value.getServiceTypeId());
}
if (value != null) {
setName(value.getName());
}
if (value != null) {
setActive(value.getActive());
}
if (value != null) {
setDescription(value.getDescription());
}
if (value != null) {
setComments(value.getComments());
}
if (value != null) {
setCreatedBy(value.getCreatedBy());
}
if (value != null) {
setUpdatedBy(value.getUpdatedBy());
}
if (value != null) {
setUpdatedOn(value.getUpdatedOn());
}
if (value != null) {
setCreatedOn(value.getCreatedOn());
}
if (value != null) {
setVersionNo(value.getVersionNo());
}
}
/**
* Return the primary key.
*
* @return Long with the primary key.
*/
@javax.persistence.Transient
public Long getPrimaryKey() {
return getServiceTypeId();
}
/**
* Set the primary key.
*
* @param primaryKey the primary key
*/
@javax.persistence.Transient
public void setPrimaryKey(Long primaryKey) {
setServiceTypeId(primaryKey);
}
/**
* Returns the value of the <code>serviceTypeId</code> property.
*
*/
@Column(name = "SERVICE_TYPE_ID" , nullable = false )
@Id @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="SERVICE_TYPE_seq")
public Long getServiceTypeId() {
return serviceTypeId;
}
/**
* Sets the value of the <code>serviceTypeId</code> property.
*
* @param serviceTypeId the value for the <code>serviceTypeId</code> property
*
*/
public void setServiceTypeId(Long serviceTypeId) {
this.serviceTypeId = serviceTypeId;
}
/**
* Returns the value of the <code>name</code> property.
*
*/
@Column(name = "NAME" , nullable = false , length=50 )
public String getName() {
return name;
}
/**
* Sets the value of the <code>name</code> property.
*
* @param name the value for the <code>name</code> property
*
* @spring.validator type="required"
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="50"
*/
public void setName(String name) {
this.name = name;
}
/**
* Returns the value of the <code>active</code> property.
*
*/
@Column(name = "IS_ACTIVE" , nullable = false )
public Boolean getActive() {
return active;
}
/**
* Sets the value of the <code>active</code> property.
*
* @param active the value for the <code>active</code> property
*
* @spring.validator type="required"
* @spring.validator type="boolean"
*/
public void setActive(Boolean active) {
this.active = active;
}
/**
* Returns the value of the <code>description</code> property.
*
*/
@Column(name = "DESCRIPTION" , length=255 )
public String getDescription() {
return description;
}
/**
* Sets the value of the <code>description</code> property.
*
* @param description the value for the <code>description</code> property
*
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="255"
*/
public void setDescription(String description) {
this.description = description;
}
/**
* Returns the value of the <code>comments</code> property.
*
*/
@Column(name = "COMMENTS" , length=255 )
public String getComments() {
return comments;
}
/**
* Sets the value of the <code>comments</code> property.
*
* @param comments the value for the <code>comments</code> property
*
* @spring.validator type="maxlength"
* @spring.validator-args arg1value="${var:maxlength}"
* @spring.validator-var name="maxlength" value="255"
*/
public void setComments(String comments) {
this.comments = comments;
}
/**
* Returns the value of the <code>updatedOn</code> property.
*
*/
@Column(name = "UPDATED_ON" )
public Date getUpdatedOn() {
return updatedOn;
}
/**
* Sets the value of the <code>updatedOn</code> property.
*
* @param updatedOn the value for the <code>updatedOn</code> property
*
*/
public void setUpdatedOn(Date updatedOn) {
this.updatedOn = updatedOn;
}
/**
* Returns the value of the <code>createdOn</code> property.
*
*/
@Column(name = "CREATED_ON" )
public Date getCreatedOn() {
return createdOn;
}
/**
* Sets the value of the <code>createdOn</code> property.
*
* @param createdOn the value for the <code>createdOn</code> property
*
*/
public void setCreatedOn(Date createdOn) {
this.createdOn = createdOn;
}
/**
* Returns the value of the <code>versionNo</code> property.
*
*/
@Version
@Column(name = "VERSION_NO" )
public Integer getVersionNo() {
return versionNo;
}
/**
* Sets the value of the <code>versionNo</code> property.
*
* @param versionNo the value for the <code>versionNo</code> property
*
*/
public void setVersionNo(Integer versionNo) {
this.versionNo = versionNo;
}
/**
* Add the related ServiceModel to this one-to-many relation.
*
* @param serviceModel object to be added.
*/
public void addServiceTypeIdServiceModel(ServiceModel serviceModel) {
serviceModel.setRelationServiceTypeIdServiceTypeModel(this);
serviceTypeIdServiceModelList.add(serviceModel);
}
/**
* Get a list of related ServiceModel objects of the ServiceTypeModel object.
* These objects are in a bidirectional one-to-many relation by the ServiceTypeId member.
*
* @return Collection of ServiceModel objects.
*
*/
@OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE,CascadeType.REFRESH}, fetch = FetchType.LAZY, mappedBy = "relationServiceTypeIdServiceTypeModel")
@JoinColumn(name = "SERVICE_TYPE_ID")
@org.hibernate.annotations.Cascade(
{org.hibernate.annotations.CascadeType.
SAVE_UPDATE,
org.hibernate.annotations.CascadeType.
PERSIST,
org.hibernate.annotations.CascadeType.
MERGE,
org.hibernate.annotations.CascadeType.
REFRESH})
public Collection<ServiceModel> getServiceTypeIdServiceModelList() throws Exception {
return serviceTypeIdServiceModelList;
}
/**
* Set a list of ServiceModel related objects to the ServiceTypeModel object.
* These objects are in a bidirectional one-to-many relation by the ServiceTypeId member.
*
* @param serviceModelList the list of related objects.
*/
public void setServiceTypeIdServiceModelList(Collection<ServiceModel> serviceModelList) throws Exception {
this.serviceTypeIdServiceModelList = serviceModelList;
}
/**
* Used by the display tag library for rendering a checkbox in the list.
* @return String with a HTML checkbox.
*/
@Transient
public String getCheckbox() {
String checkBox = "<input type=\"checkbox\" name=\"checkbox";
checkBox += "_"+ getServiceTypeId();
checkBox += "\"/>";
return checkBox;
}
/**
* Helper method for Struts with displaytag
*/
@javax.persistence.Transient
public String getPrimaryKeyParameters() {
String parameters = "";
parameters += "&serviceTypeId=" + getServiceTypeId();
return parameters;
}
/**
* Helper method for default Sorting on Primary Keys
*/
@javax.persistence.Transient
public String[] getPrimaryKeysFieldName()
{
ArrayList<String> pkFieldNameList = new ArrayList<String>();
pkFieldNameList.add("serviceTypeId");
String[] pkFieldNameArray = new String[pkFieldNameList.size()];
return (String[])pkFieldNameList.toArray(pkFieldNameArray);
}
}
Please reply me soon as i am dire need of u r help. Also suggest me if i need to use Collection or Set form ampping one to many side?.Thanks in advance.
Regards,
Shoaib Akhtar