What is interesting to me is that I have 7 entities in my project. All of them 
work fine, except that one. Here is the source for all the beans:

1. Application and Organisation have long for primary key

  | @Entity
  | @Local
  | @Table(name = "application")
  | public class Application implements Serializable{
  |     private long id;
  | 
  |     private String name;
  |     
  |     private Collection<Version> versions;
  | 
  |     public Application() {
  |     }
  | 
  |     public Application(String name) {
  |             this.name = name;
  |     }
  | 
  |     @Id
  |     @GeneratedValue(strategy = GenerationType.AUTO)
  |     public long getId() {
  |             return id;
  |     }
  | 
  |     public void setId(long id) {
  |             this.id = id;
  |     }
  | 
  |     @Column(name="name")
  |     public String getName() {
  |             return name;
  |     }
  | 
  |     public void setName(String name) {
  |             this.name = name;
  |     }
  | 
  |     @OneToMany
  |     public Collection<Version> getVersions() {
  |             return versions;
  |     }
  | 
  |     public void setVersions(Collection<Version> versions) {
  |             this.versions = versions;
  |     }
  | }
  | 

  | @Entity
  | @Local
  | @Table(name = "organisation")
  | public class Organisation implements Serializable {
  |     long id;
  | 
  |     String name;
  | 
  |     public Organisation() {
  |     }
  | 
  |     public Organisation(String name, long cityId) {
  |             this.name = name;
  |     }
  | 
  |     @Id
  |     @GeneratedValue(strategy = GenerationType.AUTO)
  |     public long getId() {
  |             return id;
  |     }
  | 
  |     public void setId(long id) {
  |             this.id = id;
  |     }
  | 
  |     @Column(name = "name")
  |     public String getName() {
  |             return name;
  |     }
  | 
  |     public void setName(String name) {
  |             this.name = name;
  |     }
  | 
  | }
  | 

2. Version entity has a PK class with two fields: versionMark and foreign key 
from Application
@Entity
  | @Local
  | @Table(name = "version")
  | public class Version implements Serializable {
  | 
  |     String versionMark;
  | 
  |     Application application;
  | 
  |     VersionPK versionPK;
  | 
  |     Collection<Edition> editions;
  | 
  |     @EmbeddedId
  |     @AttributeOverrides( {
  |                     @AttributeOverride(name = "versionMark", column = 
@Column(name = "versionMark")),
  |                     @AttributeOverride(name = "applicationId", column = 
@Column(name = "applicationId")) })
  |     public VersionPK getVersionPK() {
  |             return versionPK;
  |     }
  | 
  |     public void setVersionPK(VersionPK versionPK) {
  |             this.versionPK = versionPK;
  |     }
  | 
  |     @Column(name = "versionMark", updatable = false, insertable = false)
  |     public String getVersionMark() {
  |             return versionMark;
  |     }
  | 
  |     public void setVersionMark(String versionMark) {
  |             this.versionMark = versionMark;
  |     }
  | 
  |     @ManyToOne
  |     @JoinColumn(name = "applicationId", insertable = false, updatable = 
false)
  |     public Application getApplication() {
  |             return application;
  |     }
  | 
  |     public void setApplication(Application application) {
  |             this.application = application;
  |     }
  | 
  |     @OneToMany(cascade = CascadeType.ALL, mappedBy = "version")
  |     public Collection<Edition> getEditions() {
  |             return editions;
  |     }
  | 
  |     public void setEditions(Collection<Edition> editions) {
  |             this.editions = editions;
  |     }
  | }
  | 
and PK:

  | @Embeddable
  | public class VersionPK implements Serializable {
  | 
  |     private String versionMark;
  | 
  |     private long applicationId;
  | 
  |     public VersionPK() {
  |     }
  | 
  |     public VersionPK(String versionMark, long applicationId) {
  |             this.versionMark = versionMark;
  |             this.applicationId = applicationId;
  |     }
  | 
  |     public long getApplicationId() {
  |             return applicationId;
  |     }
  | 
  |     public void setApplicationId(long applicationId) {
  |             this.applicationId = applicationId;
  |     }
  | 
  |     public String getVersionMark() {
  |             return versionMark;
  |     }
  | 
  |     public void setVersionMark(String versionMark) {
  |             this.versionMark = versionMark;
  |     }
  | 
  |     public int hashCode() {
  |             return (int) versionMark.hashCode()
  |                             + (int) (new Long(applicationId)).hashCode();
  |     }
  | 
  |     public boolean equals(Object obj) {
  |             if (obj == this)
  |                     return true;
  |             if (!(obj instanceof VersionPK))
  |                     return false;
  |             if (obj == null)
  |                     return false;
  |             VersionPK pk = (VersionPK) obj;
  |             return pk.versionMark.equals(versionMark)
  |                             && pk.applicationId == applicationId;
  |     }
  | 
  | }
  | 

3. Finally, there is Edition entity with primary key of foreign keys from the 
Version and from the Organisation:
@Entity
  | @Local
  | @Table(name = "edition")
  | public class Edition implements Serializable {
  |     private EditionPK editionPK;
  | 
  |     private Organisation organisation;
  | 
  |     private Version version;
  | 
  |     @EmbeddedId
  |     @AttributeOverrides( {
  |                     @AttributeOverride(name = "organisationId", column = 
@Column(name = "organisationId")),
  |                     @AttributeOverride(name = "versionMark", column = 
@Column(name = "versionMark")),
  |                     @AttributeOverride(name = "applicationId", column = 
@Column(name = "applicationId")) })
  |     public EditionPK getEditionPK() {
  |             return editionPK;
  |     }
  | 
  |     public void setEditionPK(EditionPK editionPK) {
  |             this.editionPK = editionPK;
  |     }
  | 
  |     @ManyToOne(targetEntity = Organisation.class, cascade = 
CascadeType.ALL, fetch = FetchType.EAGER, optional = false)
  |     @JoinColumn(name = "organisationId", insertable = false, updatable = 
false)
  |     public Organisation getOrganisation() {
  |             return organisation;
  |     }
  | 
  |     public void setOrganisation(Organisation organisation) {
  |             this.organisation = organisation;
  |     }
  | 
  |     @ManyToOne
  |     @JoinColumns( {
  |                     @JoinColumn(name = "versionMark", insertable = false, 
updatable = false),
  |                     @JoinColumn(name = "applicationId", insertable = false, 
updatable = false) })
  |     public Version getVersion() {
  |             return version;
  |     }
  | 
  |     public void setVersion(Version version) {
  |             this.version = version;
  |     }
  | 
  |     public Edition(Organisation organisation, Version version) {
  |             this.organisation = organisation;
  |             this.version = version;
  |     }
  | 
  |     public Edition() {
  |     }
  | 
  | 
  | }
  | 
and PK:
@Embeddable
  | public class EditionPK implements Serializable {
  | 
  |     String versionMark;
  |     
  |     long applicationId;
  |     
  |     long organisationId;
  |     
  |     public EditionPK() {
  |     }
  | 
  |     public EditionPK(String versionMark, long applicationId, long 
organisationId) {
  |             this.versionMark = versionMark;
  |             this.applicationId = applicationId;
  |             this.organisationId = organisationId;
  |     }
  | 
  |     public long getApplicationId() {
  |             return applicationId;
  |     }
  | 
  |     public void setApplicationId(long applicationId) {
  |             this.applicationId = applicationId;
  |     }
  | 
  |     public String getVersionMark() {
  |             return versionMark;
  |     }
  | 
  |     public void setVersionMark(String versionMark) {
  |             this.versionMark = versionMark;
  |     }
  | 
  |     public long getOrganisationId() {
  |             return organisationId;
  |     }
  | 
  |     public void setOrganisationId(long organisationId) {
  |             this.organisationId = organisationId;
  |     }
  | 
  |     public int hashCode() {
  |             return (int) versionMark.hashCode()
  |                             + (int) (new Long(applicationId)).hashCode()
  |                             + (int) (new Long(organisationId)).hashCode();
  |     }
  | 
  |     public boolean equals(Object obj) {
  |             if (obj == this)
  |                     return true;
  |             if (!(obj instanceof VersionPK))
  |                     return false;
  |             if (obj == null)
  |                     return false;
  |             EditionPK pk = (EditionPK) obj;
  |             return pk.getVersionMark().equals(versionMark)
  |                             && pk.getApplicationId()== applicationId
  |                             && pk.getOrganisationId() == organisationId;
  |     }
  | }
  | 

Everything works fine, until I try to work with Edition. Every query works fine 
for every other bean. I'm using facade pattern. I get other entities (as 
POJOs,of course) on the client side, but Edition breaks, even if I don't send 
it. I have another bean that is @ManyToOne with Edition and when I try to do 
query within facade and to set it to that other bean it breaks within facade 
(without anything sent to client).

Can anyone tell me what's wrong?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3921129#3921129

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3921129


-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems?  Stop!  Download the new AJAX search engine that makes
searching your log files as easy as surfing the  web.  DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user

Reply via email to