Hi all,
Here are my relationships
A CONTRACT is always assigned one and only one CONTRACT_TYPE (CSA Lite, PM)
A CONTRACT_TYPE is always associated with zero or more CONTRACTs
The CONTRACT_TYPE is a static list which will not change overtime. The problem I am facing is that I doesnt want to SAVE the Contract_Type for every contract the user enters. however I just want to verify that the contract type user has selected is in the list of contracttypes in the database. I am not sure how to model this. Any help is appreciated.
Thank you in advance!
Hibernate version: 3.0
Mapping documents: <?xml version="1.0"?>
<hibernate-mapping package="com.dds.domain">
<class name="Contract">
<id name="id" column="ID">
<generator class="sequence">
<param name="sequence">HIBERNATE_SEQUENCE</param>
</generator>
</id>
<property name="date" column="DATE_SUBMITTED" type="date"/>
<many-to-one name="contractType" column="FK_CONTRACT_TYPE_ID" class="ContractType" />
</class>
</hibernate-mapping>
--------------------------------------------------------------------------------------
<?xml version="1.0"?>
<hibernate-mapping package="com.dds.domain">
<class name="ContractType" table="CONTRACT_TYPE">
<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">HIBERNATE_SEQUENCE</param>
</generator>
</id>
</class>
</hibernate-mapping>
Contract and ContractType classes public class Contract implements Serializable
{
private static final long serialVersionUID = -4266076966823864842L;
private long id;
private Date date;
private ContractType contractType;
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public ContractType getContractType() {
return contractType;
}
public void setContractType(ContractType type) {
this.contractType = type;
}
}
public class ContractType implements Serializable {
private static final long serialVersionUID = 1L;
private long id;
private
String name;
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
Code between sessionFactory.openSession() and session.close(): Session ses=sFactory.openSession();
ContractType ct=new ContractType();
Contract co=new Contract();
ct.setName("CSA Lite");
co.setDate(new Date());
co.setContractType(ct);
ses.save(ct);
ses.save(co);
ses.flush();
Name and version of the database you are using: Oracle 10g