Joined: Thu Aug 14, 2008 3:53 am Posts: 4
|
here is the source, im using xml mapping files. Im not using any JPA
package events;
public class Contact {
private Long id;
String email;
User user;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public User getUser() {
return user;
}
public void setUser(User user) {
this.user = user;
}
}
//////////////////////////////////////////////////////////////////
package events;
import java.util.*;
public class User {
private Long id;
private int age;
private String firstname;
private String lastname;
private Contact contact;
public User() {}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
private Set groups = new HashSet();
public Set getGroups() {
return groups;
}
public void setGroups(Set groups) {
this.groups = groups;
}
public void addToGroup(Group group) {
this.getGroups().add(group);
group.getParticipants().add(this);
}
public void removeFromGroup(Group group) {
this.getGroups().remove(group);
group.getParticipants().remove(this);
}
public Contact getContact() {
return contact;
}
public void setContact(Contact contact) {
this.contact = contact;
}
}
///////////////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="events.User" table="USER">
<id name="id" column="USER_ID">
<generator class="native"/>
</id>
<property name="age"/>
<property name="firstname"/>
<property name="lastname"/>
<set name="groups" table="USER_GROUP">
<key column="USER_ID"/>
<many-to-many column="GROUP_ID" class="events.Group"/>
</set>
<one-to-one name="contact" class="events.Contact"></one-to-one>
</class>
</hibernate-mapping>
///////////////////////////////////////////////////////////////////////////////
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="events.Contact" table="CONTACT" >
<id name="id" column="CONTACT_ID">
<generator class="native"/>
</id>
<property name="email" />
<one-to-one name="user" class="events.User"></one-to-one>
</class>
</hibernate-mapping>
|
|