Well, here is the full Message POJO
Code:
/*
* Message.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.recordz.ejb.entity;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* Entity class Message
*
* @author alex
*/
@Entity
@Table(name = "message")
@NamedQueries( {
@NamedQuery(name = "Message.findByIdMessage", query = "SELECT m FROM Message m WHERE m.messagePK.idMessage = :idMessage"),
@NamedQuery(name = "Message.findByRefLang", query = "SELECT m FROM Message m WHERE m.messagePK.refLang = :refLang")
})
public class Message implements Serializable {
/**
* EmbeddedId primary key field
*/
@EmbeddedId
protected MessagePK messagePK;
@Lob
@Column(name = "text", nullable = false)
private String text;
@JoinColumn(name = "ref_type", referencedColumnName = "id_type")
@ManyToOne
private Type refType;
@JoinColumn(name = "ref_lang", referencedColumnName = "id_lang", insertable = false, updatable = false)
@ManyToOne
private Lang lang;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "message")
private Collection<Category> categoryCollection;
/** Creates a new instance of Message */
public Message() {
}
/**
* Creates a new instance of Message with the specified values.
* @param messagePK the messagePK of the Message
*/
public Message(MessagePK messagePK) {
this.messagePK = messagePK;
}
/**
* Creates a new instance of Message with the specified values.
* @param messagePK the messagePK of the Message
* @param text the text of the Message
*/
public Message(MessagePK messagePK, String text) {
this.messagePK = messagePK;
this.text = text;
}
/**
* Creates a new instance of MessagePK with the specified values.
* @param refLang the refLang of the MessagePK
* @param idMessage the idMessage of the MessagePK
*/
public Message(int refLang, int idMessage) {
this.messagePK = new MessagePK(refLang, idMessage);
}
/**
* Gets the messagePK of this Message.
* @return the messagePK
*/
public MessagePK getMessagePK() {
return this.messagePK;
}
/**
* Sets the messagePK of this Message to the specified value.
* @param messagePK the new messagePK
*/
public void setMessagePK(MessagePK messagePK) {
this.messagePK = messagePK;
}
/**
* Gets the text of this Message.
* @return the text
*/
public String getText() {
return this.text;
}
/**
* Sets the text of this Message to the specified value.
* @param text the new text
*/
public void setText(String text) {
this.text = text;
}
/**
* Gets the refType of this Message.
* @return the refType
*/
public Type getRefType() {
return this.refType;
}
/**
* Sets the refType of this Message to the specified value.
* @param refType the new refType
*/
public void setRefType(Type refType) {
this.refType = refType;
}
/**
* Gets the lang of this Message.
* @return the lang
*/
public Lang getLang() {
return this.lang;
}
/**
* Sets the lang of this Message to the specified value.
* @param lang the new lang
*/
public void setLang(Lang lang) {
this.lang = lang;
}
/**
* Gets the categoryCollection of this Message.
* @return the categoryCollection
*/
public Collection<Category> getCategoryCollection() {
return this.categoryCollection;
}
/**
* Sets the categoryCollection of this Message to the specified value.
* @param categoryCollection the new categoryCollection
*/
public void setCategoryCollection(Collection<Category> categoryCollection) {
this.categoryCollection = categoryCollection;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (this.messagePK != null ? this.messagePK.hashCode() : 0);
return hash;
}
/**
* Determines whether another object is equal to this Message. The result is
* <code>true</code> if and only if the argument is not null and is a Message object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Message)) {
return false;
}
Message other = (Message)object;
if (this.messagePK != other.messagePK && (this.messagePK == null || !this.messagePK.equals(other.messagePK))) return false;
return true;
}
/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "com.recordz.ejb.entity.Message[messagePK=" + messagePK + "]";
}
}
MessagePK :
Code:
/*
* MessagePK.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.recordz.ejb.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.Embeddable;
/**
* Primary Key class MessagePK for entity class Message
*
* @author alex
*/
@Embeddable
public class MessagePK implements Serializable {
@Column(name = "id_message", nullable = false)
private int idMessage;
@Column(name = "ref_lang", nullable = false)
private int refLang;
/** Creates a new instance of MessagePK */
public MessagePK() {
}
/**
* Creates a new instance of MessagePK with the specified values.
* @param refLang the refLang of the MessagePK
* @param idMessage the idMessage of the MessagePK
*/
public MessagePK(int refLang, int idMessage) {
this.refLang = refLang;
this.idMessage = idMessage;
}
/**
* Gets the idMessage of this MessagePK.
* @return the idMessage
*/
public int getIdMessage() {
return this.idMessage;
}
/**
* Sets the idMessage of this MessagePK to the specified value.
* @param idMessage the new idMessage
*/
public void setIdMessage(int idMessage) {
this.idMessage = idMessage;
}
/**
* Gets the refLang of this MessagePK.
* @return the refLang
*/
public int getRefLang() {
return this.refLang;
}
/**
* Sets the refLang of this MessagePK to the specified value.
* @param refLang the new refLang
*/
public void setRefLang(int refLang) {
this.refLang = refLang;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (int)refLang;
hash += (int)idMessage;
return hash;
}
/**
* Determines whether another object is equal to this MessagePK. The result is
* <code>true</code> if and only if the argument is not null and is a MessagePK object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof MessagePK)) {
return false;
}
MessagePK other = (MessagePK)object;
if (this.refLang != other.refLang) return false;
if (this.idMessage != other.idMessage) return false;
return true;
}
/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "com.recordz.ejb.entity.MessagePK[refLang=" + refLang + ", idMessage=" + idMessage + "]";
}
}
Lang POJO
Code:
/*
* Lang.java
*
* Created on 21. février 2007, 09:22
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package com.recordz.ejb.entity;
import java.io.Serializable;
import java.util.Collection;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Lob;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
/**
* Entity class Lang
*
* @author alex
*/
@Entity
@Table(name = "lang")
@NamedQueries( {
@NamedQuery(name = "Lang.findByIdLang", query = "SELECT l FROM Lang l WHERE l.idLang = :idLang")
})
public class Lang implements Serializable {
@Id
@Column(name = "id_lang", nullable = false)
private Integer idLang;
@Lob
@Column(name = "name", nullable = false)
private String name;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "lang")
private Collection<Message> messageCollection;
/** Creates a new instance of Lang */
public Lang() {
}
/**
* Creates a new instance of Lang with the specified values.
* @param idLang the idLang of the Lang
*/
public Lang(Integer idLang) {
this.idLang = idLang;
}
/**
* Creates a new instance of Lang with the specified values.
* @param idLang the idLang of the Lang
* @param name the name of the Lang
*/
public Lang(Integer idLang, String name) {
this.idLang = idLang;
this.name = name;
}
/**
* Gets the idLang of this Lang.
* @return the idLang
*/
public Integer getIdLang() {
return this.idLang;
}
/**
* Sets the idLang of this Lang to the specified value.
* @param idLang the new idLang
*/
public void setIdLang(Integer idLang) {
this.idLang = idLang;
}
/**
* Gets the name of this Lang.
* @return the name
*/
public String getName() {
return this.name;
}
/**
* Sets the name of this Lang to the specified value.
* @param name the new name
*/
public void setName(String name) {
this.name = name;
}
/**
* Gets the messageCollection of this Lang.
* @return the messageCollection
*/
public Collection<Message> getMessageCollection() {
return this.messageCollection;
}
/**
* Sets the messageCollection of this Lang to the specified value.
* @param messageCollection the new messageCollection
*/
public void setMessageCollection(Collection<Message> messageCollection) {
this.messageCollection = messageCollection;
}
/**
* Returns a hash code value for the object. This implementation computes
* a hash code value based on the id fields in this object.
* @return a hash code value for this object.
*/
@Override
public int hashCode() {
int hash = 0;
hash += (this.idLang != null ? this.idLang.hashCode() : 0);
return hash;
}
/**
* Determines whether another object is equal to this Lang. The result is
* <code>true</code> if and only if the argument is not null and is a Lang object that
* has the same id field values as this object.
* @param object the reference object with which to compare
* @return <code>true</code> if this object is the same as the argument;
* <code>false</code> otherwise.
*/
@Override
public boolean equals(Object object) {
// TODO: Warning - this method won't work in the case the id fields are not set
if (!(object instanceof Lang)) {
return false;
}
Lang other = (Lang)object;
if (this.idLang != other.idLang && (this.idLang == null || !this.idLang.equals(other.idLang))) return false;
return true;
}
/**
* Returns a string representation of the object. This implementation constructs
* that representation based on the id fields.
* @return a string representation of the object.
*/
@Override
public String toString() {
return "com.recordz.ejb.entity.Lang[idLang=" + idLang + "]";
}
}
Thanks for your support Emmanuel.