• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

1-many (static list)

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There does not need to be a mapping for the static list. If you can make sure that the CONTRACT_TYPE table only contains unique entries:

Contract has a many-to-one with ContractType (FK will end up in the CONTRACT table)

when you create a new Contract just select all ContractTypes and check if the new Contract has a type that exists in the list.


pascal
 
Did you miss me? Did you miss this tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic