-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Mapping problem
PostPosted: Thu Sep 09, 2010 6:32 am 
Newbie

Joined: Wed Sep 08, 2010 8:20 am
Posts: 2
I have the followings mappings:
Code:
package com.destiny.soap.beans;

import java.io.Serializable;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

import com.destiny.soap.util.EqualsUtil;
import com.destiny.soap.util.HashCodeUtil;

@Entity
@Table(name = "soapPendingRequest")
public class PendingRequest
      implements Serializable {

   private static final long serialVersionUID = 5215116008154925704L;

   private Long id;

   private Form form;

   private boolean success;

   private String error;

   private Timestamp created;

   private Timestamp delivered;

   private Set<RequestParameter> requestParameters = new HashSet<RequestParameter>();

   private boolean locked;

   private Configuration configuration;

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

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "soapPendingRequest_key")
   public Long getId() {
      return id;
   }

   public void setSuccess(boolean success) {
      this.success = success;
   }

   @Column
   @Type(type = "yes_no")
   public boolean isSuccess() {
      return success;
   }

   public void setError(String error) {
      this.error = error;
   }

   @Column
   public String getError() {
      return error;
   }

   public void setCreated(Timestamp created) {
      this.created = created;
   }

   @Column
   public Timestamp getCreated() {
      return created;
   }

   public void setDelivered(Timestamp delivered) {
      this.delivered = delivered;
   }

   @Column
   public Timestamp getDelivered() {
      return delivered;
   }

   public void setRequestParameters(Set<RequestParameter> requestParameters) {
      this.requestParameters = requestParameters;
   }

   @OneToMany(mappedBy = "pendingRequest", cascade = CascadeType.ALL)
   public Set<RequestParameter> getRequestParameters() {
      return requestParameters;
   }

   public boolean equals(Object obj) {
      if (obj == this) {
         return true;
      }
      if (!(obj instanceof PendingRequest)) {
         return false;
      }
      PendingRequest object = (PendingRequest) obj;
      return EqualsUtil.areEqual(this.isSuccess(), object.isSuccess())
         && EqualsUtil.areEqual(this.getError(), object.getError())
         && EqualsUtil.areEqual(this.getCreated(), object.getCreated())
         && EqualsUtil.areEqual(this.getDelivered(), object.getDelivered())
         && EqualsUtil.areEqual(this.isLocked(), object.isLocked())
         && EqualsUtil.areEqual(this.getConfiguration(), object
            .getConfiguration());
   }

   public int hashCode() {
      int result = 1;
      result = HashCodeUtil.hash(result, this.isSuccess());
      result = HashCodeUtil.hash(result, this.getError());
      result = HashCodeUtil.hash(result, this.getCreated());
      result = HashCodeUtil.hash(result, this.getDelivered());
      result = HashCodeUtil.hash(result, this.isLocked());
      result = HashCodeUtil.hash(result, this.getConfiguration());
      return result;
   }

   public void setLocked(boolean locked) {
      this.locked = locked;
   }

   @Column
   @Type(type = "yes_no")
   public boolean isLocked() {
      return locked;
   }

   public void setConfiguration(Configuration configuration) {
      this.configuration = configuration;
   }

   @ManyToOne
   @JoinColumn(name = "soapConfiguration_fkey", nullable = false)
   public Configuration getConfiguration() {
      return configuration;
   }

   public void setForm(Form form) {
      this.form = form;
   }

   @ManyToOne(cascade = {CascadeType.PERSIST, CascadeType.MERGE})
   @JoinColumn(name = "form_fkey")
   public Form getForm() {
      return form;
   }
}

Code:
package com.destiny.soap.beans;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.ForceDiscriminator;

@Entity
@Table(name = "soapRequestParameter")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.STRING)
@ForceDiscriminator
public abstract class RequestParameter
      implements Serializable {

   private static final long serialVersionUID = 634271628568734918L;

   private Long id;

   private MessageParameter messageParameter;

   private PendingRequest pendingRequest;

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

   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "soapRequestParameter_key")
   public Long getId() {
      return id;
   }

   public void setMessageParameter(MessageParameter messageParameter) {
      this.messageParameter = messageParameter;
   }

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name = "soapMessageParameter_fkey")
   public MessageParameter getMessageParameter() {
      return messageParameter;
   }

   public void setPendingRequest(PendingRequest pendingRequest) {
      this.pendingRequest = pendingRequest;
   }

   @ManyToOne(fetch=FetchType.LAZY)
   @JoinColumn(name = "soapPendingRequest_fkey")
   public PendingRequest getPendingRequest() {
      return pendingRequest;
   }
}

Code:
package com.destiny.soap.beans;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;

import org.hibernate.annotations.Entity;
import org.hibernate.annotations.ForceDiscriminator;

import com.destiny.soap.util.EqualsUtil;
import com.destiny.soap.util.HashCodeUtil;

@Entity
@DiscriminatorValue(value = "requestFileParameter")
@ForceDiscriminator
public class RequestFileParameter
      extends RequestParameter {

   private static final long serialVersionUID = -846150044752695171L;

   private String path;

   private String name;

   public void setPath(String path) {
      this.path = path;
   }

   @Column
   public String getPath() {
      return path;
   }

   public void setName(String name) {
      this.name = name;
   }

   @Column
   public String getName() {
      return name;
   }

   public boolean equals(Object obj) {
      if (obj == this) {
         return true;
      }
      if (!(obj instanceof RequestFileParameter)) {
         return false;
      }
      RequestFileParameter object = (RequestFileParameter) obj;
      return EqualsUtil.areEqual(this.getName(), object.getName())
         && EqualsUtil.areEqual(this.getPath(), object.getPath())
         && EqualsUtil.areEqual(this.getMessageParameter(), object
            .getMessageParameter())
         && EqualsUtil.areEqual(this.getPendingRequest(), object
            .getPendingRequest());
   }

   public int hashCode() {
      int result = 1;
      result = HashCodeUtil.hash(result, this.getName());
      result = HashCodeUtil.hash(result, this.getPath());
      result = HashCodeUtil.hash(result, this.getMessageParameter());
      result = HashCodeUtil.hash(result, this.getPendingRequest());
      return result;
   }
}

Code:
package com.destiny.soap.beans;

import javax.persistence.Column;
import javax.persistence.DiscriminatorValue;

import org.hibernate.annotations.Entity;
import org.hibernate.annotations.ForceDiscriminator;

import com.destiny.soap.util.EqualsUtil;
import com.destiny.soap.util.HashCodeUtil;

@Entity
@DiscriminatorValue(value = "requestFieldParameter")
@ForceDiscriminator
public class RequestFieldParameter
      extends RequestParameter {

   private static final long serialVersionUID = -2489727599028611036L;

   private String value;

   public void setValue(String value) {
      this.value = value;
   }

   @Column
   public String getValue() {
      return value;
   }

   public boolean equals(Object obj) {
      if (obj == this) {
         return true;
      }
      if (!(obj instanceof RequestFieldParameter)) {
         return false;
      }
      RequestFieldParameter object = (RequestFieldParameter) obj;
      return EqualsUtil.areEqual(this.getValue(), object.getValue())
         && EqualsUtil.areEqual(this.getMessageParameter(), object
            .getMessageParameter())
         && EqualsUtil.areEqual(this.getPendingRequest(), object
            .getPendingRequest());
   }

   public int hashCode() {
      int result = 1;
      result = HashCodeUtil.hash(result, this.getValue());
      result = HashCodeUtil.hash(result, this.getMessageParameter());
      result = HashCodeUtil.hash(result, this.getPendingRequest());
      return result;
   }
}

In my test when I try loading the one to many relations getRequestParameters() from PendingRequest I get and extra "1=2" added to the query. Can anyone help? I cannot see where I am going wrong.
Below is the log and the query I am seeing:
Code:
2010-09-09 11:24:12,914 DEBUG [org.hibernate.engine.StatefulPersistenceContext] - initializing non-lazy collections
2010-09-09 11:24:12,914 DEBUG [org.hibernate.loader.Loader] - done entity load
2010-09-09 11:24:17,946 DEBUG [org.hibernate.loader.Loader] - loading collection: [com.destiny.soap.beans.PendingRequest.requestParameters#4]
2010-09-09 11:24:17,946 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2010-09-09 11:24:17,946 DEBUG [org.hibernate.SQL] -
    /* load one-to-many com.destiny.soap.beans.PendingRequest.requestParameters */ select
        requestpar0_.soapPendingRequest_fkey as soapPend4_1_,
        requestpar0_.soapRequestParameter_key as soapRequ2_1_,
        requestpar0_.soapRequestParameter_key as soapRequ2_8_0_,
        requestpar0_.soapMessageParameter_fkey as soapMess3_8_0_,
        requestpar0_.soapPendingRequest_fkey as soapPend4_8_0_
    from
        soapRequestParameter requestpar0_
    where
        1=2
        and requestpar0_.soapPendingRequest_fkey=?
2010-09-09 11:24:17,946 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open ResultSet (open ResultSets: 0, globally: 0)
2010-09-09 11:24:17,946 DEBUG [org.hibernate.loader.Loader] - result set contains (possibly empty) collection: [com.destiny.soap.beans.PendingRequest.requestParameters#4]
2010-09-09 11:24:17,946 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close ResultSet (open ResultSets: 1, globally: 1)
2010-09-09 11:24:17,946 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2010-09-09 11:24:17,946 DEBUG [org.hibernate.engine.loading.CollectionLoadContext] - 1 collections were found in result set for role: com.destiny.soap.beans.PendingRequest.requestParameters

I never get any results back from that query because of the "1=2"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.