[jboss-user] [EJB 3.0] - Re: ManyToOne and Composite Keys
jimk1723
do-not-reply at jboss.com
Mon Apr 16 14:08:00 EDT 2007
Here's the code:
| package com.mydomain.myproject;
|
| // Generated Apr 13, 2007 6:45:10 PM by Hibernate Tools 3.2.0.b9
|
| import java.util.Date;
| import java.util.HashSet;
| import java.util.Set;
| import javax.persistence.CascadeType;
| import javax.persistence.Column;
| import javax.persistence.Entity;
| import javax.persistence.FetchType;
| import javax.persistence.GeneratedValue;
| import javax.persistence.Id;
| import javax.persistence.OneToMany;
| import javax.persistence.Table;
| import javax.persistence.Temporal;
| import javax.persistence.TemporalType;
| import org.hibernate.validator.NotNull;
|
| /**
| * Department generated by hbm2java
| */
| @Entity
| @Table(name = "DEPARTMENT")
| public class Department implements java.io.Serializable {
|
| private long departmentId;
|
| private Set<DepartmentStrings> departmentStringses = new HashSet<DepartmentStrings>(
| 0);
|
| public Department() {
| }
|
| public Department(long departmentId) {
| this.departmentId = departmentId;
| }
|
| public Department(long departmentId,
| Set<DepartmentStrings> departmentStringses) {
| this.departmentId = departmentId;
|
| this.departmentStringses = departmentStringses;
| }
|
| @Id
| @Column(name = "DEPARTMENT_ID", unique = true, nullable = false, precision = 16, scale = 0)
| @NotNull
| @GeneratedValue
| public long getDepartmentId() {
| return this.departmentId;
| }
|
| public void setDepartmentId(long departmentId) {
| this.departmentId = departmentId;
| }
|
| @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "department")
| public Set<DepartmentStrings> getDepartmentStringses() {
| return this.departmentStringses;
| }
|
| public void setDepartmentStringses(
| Set<DepartmentStrings> departmentStringses) {
| this.departmentStringses = departmentStringses;
| }
|
| }
|
| package com.mydomain.myproject;
| // Generated Apr 13, 2007 6:45:10 PM by Hibernate Tools 3.2.0.b9
|
| import javax.persistence.AttributeOverride;
| import javax.persistence.AttributeOverrides;
| import javax.persistence.Column;
| import javax.persistence.EmbeddedId;
| import javax.persistence.Entity;
| import javax.persistence.FetchType;
| import javax.persistence.JoinColumn;
| import javax.persistence.ManyToOne;
| import javax.persistence.Table;
| import org.hibernate.validator.Length;
| import org.hibernate.validator.NotNull;
|
| /**
| * DepartmentStrings generated by hbm2java
| */
| @Entity
| @Table(name = "DEPARTMENT_STRINGS")
| public class DepartmentStrings implements java.io.Serializable {
|
| private DepartmentStringsId id;
| private Department department;
| private String name;
|
| public DepartmentStrings() {
| }
|
| public DepartmentStrings(DepartmentStringsId id, Department department) {
| this.id = id;
| this.department = department;
| }
| public DepartmentStrings(DepartmentStringsId id, Department department,
| String name) {
| this.id = id;
| this.department = department;
| this.name = name;
| }
|
| @EmbeddedId
| @AttributeOverrides({
| @AttributeOverride(name = "departmentId", column = @Column(name = "DEPARTMENT_ID", nullable = false, precision = 16, scale = 0)),
| @AttributeOverride(name = "langCode", column = @Column(name = "LANG_CODE", nullable = false, length = 5))})
| @NotNull
| public DepartmentStringsId getId() {
| return this.id;
| }
|
| public void setId(DepartmentStringsId id) {
| this.id = id;
| }
| @ManyToOne(fetch = FetchType.LAZY)
| @JoinColumn(name = "DEPARTMENT_ID", nullable = false, insertable = false, updatable = false)
| @NotNull
| public Department getDepartment() {
| return this.department;
| }
|
| public void setDepartment(Department department) {
| this.department = department;
| }
|
| @Column(name = "NAME", length = 4000)
| @Length(max = 4000)
| public String getName() {
| return this.name;
| }
|
| public void setName(String name) {
| this.name = name;
| }
|
| }
|
| package com.mydomain.myproject;
| // Generated Apr 13, 2007 6:45:10 PM by Hibernate Tools 3.2.0.b9
|
| import javax.persistence.Column;
| import javax.persistence.Embeddable;
| import org.hibernate.validator.Length;
| import org.hibernate.validator.NotNull;
|
| /**
| * DepartmentStringsId generated by hbm2java
| */
| @Embeddable
| public class DepartmentStringsId implements java.io.Serializable {
|
| private long departmentId;
| private String langCode;
|
| public DepartmentStringsId() {
| }
|
| public DepartmentStringsId(long departmentId, String langCode) {
| this.departmentId = departmentId;
| this.langCode = langCode;
| }
|
| @Column(name = "DEPARTMENT_ID", nullable = false, precision = 16, scale = 0)
| @NotNull
| public long getDepartmentId() {
| return this.departmentId;
| }
|
| public void setDepartmentId(long departmentId) {
| this.departmentId = departmentId;
| }
|
| @Column(name = "LANG_CODE", nullable = false, length = 5)
| @NotNull
| @Length(max = 5)
| public String getLangCode() {
| return this.langCode;
| }
|
| public void setLangCode(String langCode) {
| this.langCode = langCode;
| }
|
| public boolean equals(Object other) {
| if ((this == other))
| return true;
| if ((other == null))
| return false;
| if (!(other instanceof DepartmentStringsId))
| return false;
| DepartmentStringsId castOther = (DepartmentStringsId) other;
|
| return (this.getDepartmentId() == castOther.getDepartmentId())
| && ((this.getLangCode() == castOther.getLangCode()) || (this
| .getLangCode() != null
| && castOther.getLangCode() != null && this
| .getLangCode().equals(castOther.getLangCode())));
| }
|
| public int hashCode() {
| int result = 17;
|
| result = 37 * result + (int) this.getDepartmentId();
| result = 37 * result
| + (getLangCode() == null ? 0 : this.getLangCode().hashCode());
| return result;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4037667#4037667
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4037667
More information about the jboss-user
mailing list