Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Converting from Hibernate composite-element mapping
Converting from Hibernate composite-element mapping [message #385169] Mon, 29 December 2008 19:54 Go to next message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
Dear members,

I cannot seem to figure out how to convert composite-element mappings from
Hibernate to JPA (I am using xml rather than annotations). The senario
should not be too uncommon: I have patient entities in a many-to-many
association with diagnosis (Icdm) entities. However, the join table,
patient_icdm, needs to have additional qualifying fields, i.e. sequence,
date of diagnosis, etc. The only way I have seen to do this in JPA is to
map the PersonIcdm object as an entity. The current table created with
the composite-element mapping does not have a primary key ( Hibernate
creates a run-time composite-primary-key for deletes comprised of all the
fields of the composite-element ). In order to do this in JPA, the
elements of the primary-key class have to be primitives or
primitive-wrappers, or Dates. But this join-object is joining entities:
Person and Diagnosis. How do I go about this? Here are my objects and
mappings:

public class Patient implements Serializable
{
private long id;
private String firstName;
private String lastName;
private Address address;
private List<PatientIcdm> PatientIcdms = new ArrayList<PatientIcdm>();
private static final long serialVersionUID = 1L;

public Patient()
{
super();
}

public long getId()
{
return this.id;
}

public void setId( long id )
{
this.id = id;
}

public String getFirstName()
{
return this.firstName;
}

public void setFirstName( String firstName )
{
this.firstName = firstName;
}

public String getLastName()
{
return this.lastName;
}

public void setLastName( String lastName )
{
this.lastName = lastName;
}

public Address getAddress()
{
return this.address;
}

public void setAddress( Address address )
{
this.address = address;
}

public String toString()
{
return firstName + " " + lastName;
}

public List<PatientIcdm> getPatientIcdms()
{
return patientIcdms;
}

public void setPatientIcdms( List<PatientIcdm> patientIcdms )
{
this.patientIcdms = patientIcdms;
}
}

public class PatientIcdm
{
private int sequence;
private Patient patient;
private Icdm icdm;

public int getSequence()
{
return sequence;
}
public void setSequence( int sequence )
{
this.sequence = sequence;
}
public Patient getPatient()
{
return patient;
}
public void setPatient( Patient Patient )
{
this.patient = patient;
}
public Icdm getIcdm()
{
return icdm;
}
public void setIcdm( Icdm icdm )
{
this.icdm = icdm;
}
}

public class Icdm
{
private int icdmId;
private String name;
private String description;

public String getName()
{
return name;
}
public void setName( String name )
{
this.name = name;
}
public String getDescription()
{
return description;
}
public void setDescription( String description )
{
this.description = description;
}
public int getIcdmId()
{
return icdmId;
}
public void setIcdmId( int icdmId )
{
this.icdmId = icdmId;
}
}

hibernate.hbm.xml:

<bag name="patientIcdms" table="patient_icdm"
cascade="save-update,delete,evict,refresh" order-by="paticdm_seq_nbr">
<key column="paticdm_pat_id"/>
<composite-element class="com.moms.models.PatientIcdm">
<many-to-one name="icdm" column="paticdm_icdm_id"
class="com.moms.models.Icdm" cascade="save-update,evict,refresh"/>
<property name="sequence" column="paticdm_seq_nbr" type="int"/>
</composite-element>
</bag>

orm.xml:

<entity-mappings>
<entity class="quickstart.demo.model.Person" access="PROPERTY">
<table name="person">
</table>
<attributes>
<id name="id">
<column name="person_id"/>
<generated-value generator="person_seq" strategy="SEQUENCE" />
<sequence-generator name="person_seq" allocation-size="1"
initial-value="1" />
</id>
<basic name="firstName">
</basic>
<basic name="lastName">
<column column-definition="type text"/>
</basic>
<many-to-one name="address" fetch="LAZY">
<join-column name="address_id" referenced-column-name="address_id"
/>
<cascade>
<cascade-all />
</cascade>
</many-to-one>
</attributes>
</entity>

<entity class="quickstart.demo.model.Icdm" access="PROPERTY">
<table name="icdm"></table>
<attributes>
<id name="icdmId">
<column name="icdm_id" />
<generated-value generator="icdm_seq" strategy="SEQUENCE" />
<sequence-generator name="icdm_seq" allocation-size="1"
initial-value="1" />
</id>
<basic name="name" />
<basic name="description" />
</attributes>
</entity>

</entity-mappings>
Re: Converting from Hibernate composite-element mapping [message #385170 is a reply to message #385169] Tue, 30 December 2008 22:04 Go to previous message
David J Rericha is currently offline David J RerichaFriend
Messages: 13
Registered: July 2009
Junior Member
Never mind. I found
http://dev.eclipse.org/newslists/news.eclipse.rt.eclipselink /msg00297.html.
Apologies.
Previous Topic:how to extend the DDL output (indexes, ..)
Next Topic:EclipseLink as alternative to Hibernate in Swing App
Goto Forum:
  


Current Time: Tue Apr 23 09:32:21 GMT 2024

Powered by FUDForum. Page generated in 0.03206 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top