-->
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.  [ 7 posts ] 
Author Message
 Post subject: Native SQL Query to Hibernate Query using Criteria
PostPosted: Sat Apr 12, 2014 9:12 am 
Newbie

Joined: Sat Apr 12, 2014 9:02 am
Posts: 4
Hi,

I am new to Hibernate and having trouble converting the below Native SQL query to Hibernate Query using Criteria.


SELECT REL_ROL4.RELATED_RELATIONSHIP_ID AS RELATIONSHIP_ID ,
REL_ROL1.RELATED_LEGAL_ENTITY_ID AS provider_id,
REL_ROL2.RELATED_LEGAL_ENTITY_ID AS legal_entity_of_interest ,
REL_ROL3.RELATED_LEGAL_ENTITY_ID AS consumer_id
FROM RELATIONSHIP_ROLE REL_ROL4
JOIN RELATIONSHIP_ROLE REL_ROL1
ON REL_ROL4.RELATED_RELATIONSHIP_ID = REL_ROL1.RELATIONSHIP_ID
JOIN RELATIONSHIP_ROLE REL_ROL2
ON REL_ROL1.RELATIONSHIP_ID = REL_ROL2.RELATIONSHIP_ID
JOIN RELATIONSHIP_ROLE REL_ROL3
ON REL_ROL4.RELATIONSHIP_ID = REL_ROL3.RELATIONSHIP_ID
JOIN provider prov
ON REL_ROL1.RELATED_LEGAL_ENTITY_ID = prov.LEGAL_ENTITY_ID
JOIN consumer cons
ON REL_ROL3.RELATED_LEGAL_ENTITY_ID = cons.LEGAL_ENTITY_ID
WHERE REL_ROL3.RELATED_LEGAL_ENTITY_ID =1251
AND REL_ROL2.RELATED_LEGAL_ENTITY_ID != REL_ROL1.RELATED_LEGAL_ENTITY_ID;

Please help.


Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Mon Apr 14, 2014 3:44 am 
Hibernate Team
Hibernate Team

Joined: Fri Sep 09, 2011 3:18 am
Posts: 295
Hi,
Can you give us some more information about the model? Which entities are involved?


Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Tue Apr 15, 2014 12:44 am 
Newbie

Joined: Sat Apr 12, 2014 9:02 am
Posts: 4
I have removed the import and package statement.

Code:
@Entity
@Table(name = "PROVIDER")
public class Provider implements java.io.Serializable {

   private static final long serialVersionUID = 5020996201673979696L;
   private Long providerId;
   private LegalEntity legalEntity;
   private String activeInd;
   private String updateUser;
   private Date updateDate;

   public Provider() {
      
      
   }

   public Provider(Long providerId, LegalEntity legalEntity,
         String activeInd, String updateUser, Date updateDate) {
      this.providerId = providerId;
      this.legalEntity = legalEntity;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
   }

   @Id
   @Column(name = "PROVIDER_ID", unique = true, nullable = false, precision = 22, scale = 0)
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ProviderGenerator")
   @SequenceGenerator(name="ProviderGenerator", sequenceName="PROVIDER_SEQ")
   public Long getProviderId() {
      return this.providerId;
   }

   public void setProviderId(Long providerId) {
      this.providerId = providerId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "LEGAL_ENTITY_ID", nullable = false)
   public LegalEntity getLegalEntity() {
      return this.legalEntity;
   }

   public void setLegalEntity(LegalEntity legalEntity) {
      this.legalEntity = legalEntity;
   }

   @Column(name = "ACTIVE_IND", nullable = false, length = 1)
   public String getActiveInd() {
      return this.activeInd;
   }

   public void setActiveInd(String activeInd) {
      this.activeInd = activeInd;
   }

   @Column(name = "UPDATE_USER", nullable = false, length = 20)
   public String getUpdateUser() {
      return this.updateUser;
   }

   public void setUpdateUser(String updateUser) {
      this.updateUser = updateUser;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "UPDATE_DATE", nullable = false, length = 7)
   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

}



Code:
@Entity
@Table(name = "RELATIONSHIP_ROLE")
public class RelationshipRole implements java.io.Serializable {

   private static final long serialVersionUID = 6624618087181742424L;
   private BigDecimal relationshipRoleId;
   private RelationshipRoleType relationshipRoleType;
   private Relationship relationshipByRelationshipId;
   private LegalEntity legalEntity;
   private Relationship relationshipByRelatedRelationshipId;
   private String activeInd;
   private String updateUser;
   private Date updateDate;
   private BigDecimal sourceId;

   public RelationshipRole() {
   }

   public RelationshipRole(BigDecimal relationshipRoleId,
         RelationshipRoleType relationshipRoleType, String activeInd,
         String updateUser, Date updateDate) {
      this.relationshipRoleId = relationshipRoleId;
      this.relationshipRoleType = relationshipRoleType;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
   }

   public RelationshipRole(BigDecimal relationshipRoleId,
         RelationshipRoleType relationshipRoleType,
         Relationship relationshipByRelationshipId, LegalEntity legalEntity,
         Relationship relationshipByRelatedRelationshipId, String activeInd,
         String updateUser, Date updateDate, BigDecimal sourceId) {
      this.relationshipRoleId = relationshipRoleId;
      this.relationshipRoleType = relationshipRoleType;
      this.relationshipByRelationshipId = relationshipByRelationshipId;
      this.legalEntity = legalEntity;
      this.relationshipByRelatedRelationshipId = relationshipByRelatedRelationshipId;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
      this.sourceId = sourceId;
   }

   @Id
   @Column(name = "RELATIONSHIP_ROLE_ID", unique = true, nullable = false, precision = 22, scale = 0)
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="RelRoleSeqGenerator")
   @SequenceGenerator(name="RelRoleSeqGenerator", sequenceName="RELATIONSHIP_ROLE_SEQ")   
   public BigDecimal getRelationshipRoleId() {
      return this.relationshipRoleId;
   }

   public void setRelationshipRoleId(BigDecimal relationshipRoleId) {
      this.relationshipRoleId = relationshipRoleId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "RELATIONSHIP_ROLE_CD", nullable = false)
   public RelationshipRoleType getRelationshipRoleType() {
      return this.relationshipRoleType;
   }

   public void setRelationshipRoleType(
         RelationshipRoleType relationshipRoleType) {
      this.relationshipRoleType = relationshipRoleType;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "RELATIONSHIP_ID")
   public Relationship getRelationshipByRelationshipId() {
      return this.relationshipByRelationshipId;
   }

   public void setRelationshipByRelationshipId(
         Relationship relationshipByRelationshipId) {
      this.relationshipByRelationshipId = relationshipByRelationshipId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "RELATED_LEGAL_ENTITY_ID")
   public LegalEntity getLegalEntity() {
      return this.legalEntity;
   }

   public void setLegalEntity(LegalEntity legalEntity) {
      this.legalEntity = legalEntity;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "RELATED_RELATIONSHIP_ID")
   public Relationship getRelationshipByRelatedRelationshipId() {
      return this.relationshipByRelatedRelationshipId;
   }

   public void setRelationshipByRelatedRelationshipId(
         Relationship relationshipByRelatedRelationshipId) {
      this.relationshipByRelatedRelationshipId = relationshipByRelatedRelationshipId;
   }

   @Column(name = "ACTIVE_IND", nullable = false, length = 1)
   public String getActiveInd() {
      return this.activeInd;
   }

   public void setActiveInd(String activeInd) {
      this.activeInd = activeInd;
   }

   @Column(name = "UPDATE_USER", nullable = false, length = 20)
   public String getUpdateUser() {
      return this.updateUser;
   }

   public void setUpdateUser(String updateUser) {
      this.updateUser = updateUser;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "UPDATE_DATE", nullable = false, length = 7)
   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

   @Column(name = "SOURCE_ID", precision = 22, scale = 0)
   public BigDecimal getSourceId() {
      return this.sourceId;
   }

   public void setSourceId(BigDecimal sourceId) {
      this.sourceId = sourceId;
   }

}


Code:
@Entity
@Table(name = "CONSUMER")
public class Consumer implements java.io.Serializable {

   /**
    *
    */
   private static final long serialVersionUID = 1L;
   private Long consumerId;
   private String emailDomain;
   private LegalEntity legalEntity;
   private String activeInd;
   private String updateUser;
   private Date updateDate;
   private Long sourceId;

   public Consumer() {
   }

   public Consumer(Long consumerId, String activeInd, String updateUser,
         Date updateDate) {
      this.consumerId = consumerId;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
   }

   public Consumer(Long consumerId, String emailDomain, Long legalEntityId,
         String activeInd, String updateUser, Date updateDate,
         Long sourceId) {
      this.consumerId = consumerId;
      this.emailDomain = emailDomain;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
      this.sourceId = sourceId;
   }

   @Id
   @Column(name = "CONSUMER_ID", unique = true, nullable = false, precision = 22, scale = 0)
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="ConsumerGenerator")
   @SequenceGenerator(name="ConsumerGenerator", sequenceName="CONSUMER_SEQ")
   public Long getConsumerId() {
      return this.consumerId;
   }

   public void setConsumerId(Long consumerId) {
      this.consumerId = consumerId;
   }

   @Column(name = "EMAIL_DOMAIN", length = 100)
   public String getEmailDomain() {
      return this.emailDomain;
   }

   public void setEmailDomain(String emailDomain) {
      this.emailDomain = emailDomain;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "LEGAL_ENTITY_ID", nullable = false)
   public LegalEntity getLegalEntity() {
      return this.legalEntity;
   }

   public void setLegalEntity(LegalEntity legalEntity) {
      this.legalEntity = legalEntity;
   }

   @Column(name = "ACTIVE_IND", nullable = false, length = 1)
   public String getActiveInd() {
      return this.activeInd;
   }

   public void setActiveInd(String activeInd) {
      this.activeInd = activeInd;
   }

   @Column(name = "UPDATE_USER", nullable = false, length = 20)
   public String getUpdateUser() {
      return this.updateUser;
   }

   public void setUpdateUser(String updateUser) {
      this.updateUser = updateUser;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "UPDATE_DATE", nullable = false, length = 7)
   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

   @Column(name = "SOURCE_ID", precision = 22, scale = 0)
   public Long getSourceId() {
      return this.sourceId;
   }

   public void setSourceId(Long sourceId) {
      this.sourceId = sourceId;
   }

}


Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Tue Apr 15, 2014 10:38 pm 
Newbie

Joined: Mon Apr 14, 2014 11:03 am
Posts: 8
Location: Orlando, FL
There are some things that should be left in SQL and/or HQL. I believe this may be one of those cases.

You forgot to include some of the Entities in your code as well. Relationship, RelationshipRoleType, LegalEntity are the ones I think.

This is as far as I got before my head started to hurt. The Criteria API is still based off the concept of generating an HQL statement. So the same inherent restrictions still apply. You can't do joins across different tables in the same manner that you would in SQL. The joining table typically has to be a foreign entity on your original entity. The only way to even remotely accomplish this is with DetachedCriteria and very clever ways of joining them together.

Code:
      DetachedCriteria rle1 = DetachedCriteria.forClass(RelationshipRole.class, "rle1");
      rle1.setProjection(Projections.property("relationshipRoleId"));

      DetachedCriteria rle1a = DetachedCriteria.forClass(RelationshipRole.class, "rle1a");
      rle1a.setProjection(Projections.property("legalEntity"));
      rle1a.add(Subqueries.propertyEq("relationshipRoleId", rle1));

      DetachedCriteria rle2 = DetachedCriteria.forClass(RelationshipRole.class);
      rle2.add(Subqueries.propertyEq("relationshipRoleId", rle1));
      rle2.add(Subqueries.propertyNe("legalEntity", rle1a));

      DetachedCriteria rle4 = DetachedCriteria.forClass(RelationshipRole.class);
      rle4.add(Subqueries.propertyEq("relationshipByRelatedRelationshipId", rle1));
      
      DetachedCriteria rle3 = DetachedCriteria.forClass(RelationshipRole.class);
      rle3.setProjection(Projections.property("relationshipRoleId"));
      rle3.add(Subqueries.propertyEq("relationshipRoleId", rle4));
      rle3.add(Restrictions.eq("id", "1531"));


Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Wed Apr 16, 2014 1:18 am 
Newbie

Joined: Sat Apr 12, 2014 9:02 am
Posts: 4
Hi,
I have attached the Relationship, RelationshipRoleType, LegalEntity entities.

Code:

@Entity
@Table(name = "LEGAL_ENTITY")
public class LegalEntity extends BaseModel {

   private static final long serialVersionUID = -1026643587757325475L;

   @Id
   @Column(name = "LEGAL_ENTITY_ID", unique = true, nullable = false)
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="LegalSeqGenerator")
   @SequenceGenerator(name="LegalSeqGenerator", sequenceName="LEGAL_ENTITY_SEQ")
   private Long legalEntityId;
   
   @Column(name = "CRED_LEI")
   private Long credLeId;
   
   @Column(name = "LEI")
   private String lei;
   
   @Column(name = "LEI_SOURCE")
   private String leiSource;
   
   @Column(name = "AVID")
   private BigDecimal avid;
   
   @Column(name = "GIIN")
   private String giin;
   
   @Column(name = "ENTITY_LEGAL_NAME", nullable = false)
   private String entityLegalName;

   @Column(name = "SOURCE_TYPE_CD", nullable = false)
   private String sourceTypeCd;
   
   @Column(name = "SOURCE_ID")
   private Long sourceId;

   @Column(name = "URL")
   private String URL;

   /*@Column(name = "PRIMARY_BUSINESS_PURPOSE_CD", nullable = false)
   private String primaryBusinessPurposeCd;*/

   @OneToOne
   @JoinColumn(name="PRIMARY_BUSINESS_PURPOSE_CD")
   private BusinessPurposeData businessPurpose;
   
   public BusinessPurposeData getBusinessPurpose() {
      return businessPurpose;
   }

   public void setBusinessPurpose(BusinessPurposeData businessPurpose) {
      this.businessPurpose = businessPurpose;
   }
   
   
   @OneToOne
   @JoinColumn(name="LEGAL_STRUCTURE_ID")
   private LegalStructure legalStructure;
   
   @Transient
   private BigDecimal leEntityHistId;
   
   public LegalStructure getLegalStructure() {
      return legalStructure;
   }

   public void setLegalStructure(LegalStructure legalStructure) {
      this.legalStructure = legalStructure;
   }
   
   @OneToOne
   @JoinColumn(name="GLOBAL_STRUCTURE_ID",insertable = false,updatable = false)
   private LegalStructure globalStructure;
   
   

   public LegalStructure getGlobalStructure() {
      return globalStructure;
   }

   public void setGlobalStructure(LegalStructure globalStructure) {
      this.globalStructure = globalStructure;
   }

   public LegalEntityTax getLegalEntityTax() {
      return legalEntityTax;
   }

   public void setLegalEntityTax(LegalEntityTax legalEntityTax) {
      this.legalEntityTax = legalEntityTax;
   }


   @Column(name = "FORMATION_STATUS_CD", nullable = false)
   private String formationStatusCd;

   @Column(name = "CONSORTIUM_STATUS_CD", nullable = false)
   private String consortiumStatus;
   
   @Column(name="CRED_RISK_RATING")
   private String credRiskRating;
   
   @Column(name="BASE_LEGAL_ENTITY_ID")
   private Long baseLegalEntityId;
   
   @Column(name="ANGLECIZED_LEGAL_NAME")
   private String anglecizedLegalName;
   
   @Transient
   private List<LegalEntityAddress> legalEntityAdresses;
   
   @Transient
   private LeClassificationFetch leClassification;
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private Set<LegalEntityOtherName> othernames = new HashSet<LegalEntityOtherName>();
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private Set<LegalEntityExchange> exchangeList = new HashSet<LegalEntityExchange>();
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private Set<LeRegulatoryListing> regulatoryListing = new HashSet<LeRegulatoryListing>();
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private Set<LegalEntityIdentity> legalEntityIdentities = new HashSet<LegalEntityIdentity>();

   @OneToOne(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private LegalEntityTax legalEntityTax;
   
   @OneToOne(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private LeIndividual leIndividual;
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "legalEntity")
   private Set<Provider> providers = new HashSet<Provider>();
   
   public Set<LegalEntityExchange> getExchangeList() {
      return exchangeList;
   }

   public void setExchangeList(Set<LegalEntityExchange> exchangeList) {
      this.exchangeList = exchangeList;
   }

   public Set<LeRegulatoryListing> getRegulatoryListing() {
      return regulatoryListing;
   }

   public void setRegulatoryListing(Set<LeRegulatoryListing> regulatoryListing) {
      this.regulatoryListing = regulatoryListing;
   }

   
   public Set<LegalEntityIdentity> getLegalEntityIdentities() {
      return legalEntityIdentities;
   }

   public Set<LegalEntityOtherName> getOthernames() {
      return othernames;
   }

   public void setOthernames(Set<LegalEntityOtherName> othernames) {
      this.othernames = othernames;
   }

   public void setLegalEntityIdentities(
         Set<LegalEntityIdentity> legalEntityIdentities) {
      this.legalEntityIdentities = legalEntityIdentities;
   }

   public LegalEntity() {
   }

   public Long getLegalEntityId() {
      return legalEntityId;
   }

   public void setLegalEntityId(Long legalEntityId) {
      this.legalEntityId = legalEntityId;
   }

   public String getEntityLegalName() {
      return entityLegalName;
   }

   public void setEntityLegalName(String entityLegalName) {
      this.entityLegalName = entityLegalName;
   }

   public String getSourceTypeCd() {
      return sourceTypeCd;
   }

   public void setSourceTypeCd(String sourceTypeCd) {
      this.sourceTypeCd = sourceTypeCd;
   }

   public Long getSourceId() {
      return sourceId;
   }

   public void setSourceId(Long sourceId) {
      this.sourceId = sourceId;
   }

   public String getCredRiskRating() {
      return credRiskRating;
   }

   public void setCredRiskRating(String credRiskRating) {
      this.credRiskRating = credRiskRating;
   }

   public String getURL() {
      return URL;
   }

   public void setURL(String uRL) {
      URL = uRL;
   }


   public String getFormationStatusCd() {
      return formationStatusCd;
   }

   public void setFormationStatusCd(String formationStatusCd) {
      this.formationStatusCd = formationStatusCd;
   }

   public String getConsortiumStatus() {
      return consortiumStatus;
   }

   public void setConsortiumStatus(String consortiumStatus) {
      this.consortiumStatus = consortiumStatus;
   }

   public Long getBaseLegalEntityId() {
      return baseLegalEntityId;
   }

   public void setBaseLegalEntityId(Long baseLegalEntityId) {
      this.baseLegalEntityId = baseLegalEntityId;
   }
   
   public String getAnglecizedLegalName() {
      return anglecizedLegalName;
   }

   public void setAnglecizedLegalName(String anglecizedLegalName) {
      this.anglecizedLegalName = anglecizedLegalName;
   }

   public Long getCredLeId() {
      return credLeId;
   }

   public void setCredLeId(Long credLeId) {
      this.credLeId = credLeId;
   }

   public List<LegalEntityAddress> getLegalEntityAdresses() {
      return legalEntityAdresses;
   }

   public void setLegalEntityAdresses(List<LegalEntityAddress> legalEntityAdresses) {
      this.legalEntityAdresses = legalEntityAdresses;
   }
   
   public LegalEntityTax getLeTax() {
      return this.legalEntityTax;
   }


   /**
    * @return the lei
    */
   public String getLei() {
      return lei;
   }

   /**
    * @param lei the lei to set
    */
   public void setLei(String lei) {
      this.lei = lei;
   }

   /**
    * @return the leiSource
    */
   public String getLeiSource() {
      return leiSource;
   }

   /**
    * @param leiSource the leiSource to set
    */
   public void setLeiSource(String leiSource) {
      this.leiSource = leiSource;
   }

   /**
    * @return the avid
    */
   public BigDecimal getAvid() {
      return avid;
   }

   /**
    * @param avid the avid to set
    */
   public void setAvid(BigDecimal avid) {
      this.avid = avid;
   }

   /**
    * @return the giin
    */
   public String getGiin() {
      return giin;
   }

   /**
    * @param giin the giin to set
    */
   public void setGiin(String giin) {
      this.giin = giin;
   }

   public void setLeTax(LegalEntityTax legalEntityTax) {
      this.legalEntityTax = legalEntityTax;
   }
   
   public Set<Provider> getProviders() {
      return this.providers;
   }

   public void setProviders(Set<Provider> providers) {
      this.providers = providers;
   }

   public LeClassificationFetch getLeClassification() {
      return leClassification;
   }

   public void setLeClassification(LeClassificationFetch leClassification) {
      this.leClassification = leClassification;
   }

   public BigDecimal getLeEntityHistId() {
      return leEntityHistId;
   }

   public void setLeEntityHistId(BigDecimal leEntityHistId) {
      this.leEntityHistId = leEntityHistId;
   }

   /**
    * @return the leIndividual
    */
   public LeIndividual getLeIndividual() {
      return leIndividual;
   }

   /**
    * @param leIndividual the leIndividual to set
    */
   public void setLeIndividual(LeIndividual leIndividual) {
      this.leIndividual = leIndividual;
   }
}


Code:
@Entity
@Table(name = "RELATIONSHIP_ROLE_TYPE", schema = "CRED_MDM")
public class RelationshipRoleType implements java.io.Serializable {

   private String relationshipRoleCd;
   private String relationshipRoleDesc;
   private String activeInd;
   private String updateUser;
   private Date updateDate;
   private Set<RelationshipRole> relationshipRoles = new HashSet<RelationshipRole>(
         0);

   public RelationshipRoleType() {
   }

   public RelationshipRoleType(String relationshipRoleCd,
         String relationshipRoleDesc, String activeInd, String updateUser,
         Date updateDate) {
      this.relationshipRoleCd = relationshipRoleCd;
      this.relationshipRoleDesc = relationshipRoleDesc;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
   }

   public RelationshipRoleType(String relationshipRoleCd,
         String relationshipRoleDesc, String activeInd, String updateUser,
         Date updateDate, Set<RelationshipRole> relationshipRoles) {
      this.relationshipRoleCd = relationshipRoleCd;
      this.relationshipRoleDesc = relationshipRoleDesc;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
      this.relationshipRoles = relationshipRoles;
   }

   @Id
   @Column(name = "RELATIONSHIP_ROLE_CD", unique = true, nullable = false, length = 15)
   public String getRelationshipRoleCd() {
      return this.relationshipRoleCd;
   }

   public void setRelationshipRoleCd(String relationshipRoleCd) {
      this.relationshipRoleCd = relationshipRoleCd;
   }

   @Column(name = "RELATIONSHIP_ROLE_DESC", nullable = false, length = 100)
   public String getRelationshipRoleDesc() {
      return this.relationshipRoleDesc;
   }

   public void setRelationshipRoleDesc(String relationshipRoleDesc) {
      this.relationshipRoleDesc = relationshipRoleDesc;
   }

   @Column(name = "ACTIVE_IND", nullable = false, length = 1)
   public String getActiveInd() {
      return this.activeInd;
   }

   public void setActiveInd(String activeInd) {
      this.activeInd = activeInd;
   }

   @Column(name = "UPDATE_USER", nullable = false, length = 20)
   public String getUpdateUser() {
      return this.updateUser;
   }

   public void setUpdateUser(String updateUser) {
      this.updateUser = updateUser;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "UPDATE_DATE", nullable = false, length = 7)
   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "relationshipRoleType")
   public Set<RelationshipRole> getRelationshipRoles() {
      return this.relationshipRoles;
   }

   public void setRelationshipRoles(Set<RelationshipRole> relationshipRoles) {
      this.relationshipRoles = relationshipRoles;
   }

}


Code:
@Entity
@Table(name = "RELATIONSHIP")
public class Relationship implements java.io.Serializable {

   private static final long serialVersionUID = -8053796894520890075L;
   private BigDecimal relationshipId;
   private RelationshipType relationshipType;
   private Date startDate;
   private Date endDate;
   private String activeInd;
   private String updateUser;
   private Date updateDate;
   private BigDecimal sourceId;
   private Long relationshipStatusId;
   
   private Set<RelationshipRole> relationshipRolesForRelationshipId = new HashSet<RelationshipRole>(
         0);
   private Set<RelationshipRole> relationshipRolesForRelatedRelationshipId = new HashSet<RelationshipRole>(
         0);
   private Set<Permission> permissions = new HashSet<Permission>(0);
   private Set<EvidenceSource> evidenceSources = new HashSet<EvidenceSource>(0);

   public Relationship() {
   }

   public Relationship(BigDecimal relationshipId,
         RelationshipType relationshipType, Date startDate,
         String activeInd, String updateUser, Date updateDate) {
      this.relationshipId = relationshipId;
      this.relationshipType = relationshipType;
      this.startDate = startDate;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
   }

   public Relationship(BigDecimal relationshipId,
         RelationshipType relationshipType, Date startDate, Date endDate,
         String activeInd, String updateUser, Date updateDate,
         BigDecimal sourceId,
         Set<RelationshipRole> relationshipRolesForRelationshipId,
         Set<RelationshipRole> relationshipRolesForRelatedRelationshipId,
         Set<Permission> permissions) {
      this.relationshipId = relationshipId;
      this.relationshipType = relationshipType;
      this.startDate = startDate;
      this.endDate = endDate;
      this.activeInd = activeInd;
      this.updateUser = updateUser;
      this.updateDate = updateDate;
      this.sourceId = sourceId;
      this.relationshipRolesForRelationshipId = relationshipRolesForRelationshipId;
      this.relationshipRolesForRelatedRelationshipId = relationshipRolesForRelatedRelationshipId;
      this.permissions = permissions;
   }

   @Id
   @Column(name = "RELATIONSHIP_ID", unique = true, nullable = false, precision = 22, scale = 0)
   @GeneratedValue(strategy=GenerationType.SEQUENCE, generator="RelSeqGenerator")
   @SequenceGenerator(name="RelSeqGenerator", sequenceName="RELATIONSHIP_SEQ")      
   public BigDecimal getRelationshipId() {
      return this.relationshipId;
   }

   public void setRelationshipId(BigDecimal relationshipId) {
      this.relationshipId = relationshipId;
   }

   @ManyToOne(fetch = FetchType.LAZY)
   @JoinColumn(name = "RELATIONSHIP_TYPE_CD", nullable = false)
   public RelationshipType getRelationshipType() {
      return this.relationshipType;
   }

   public void setRelationshipType(RelationshipType relationshipType) {
      this.relationshipType = relationshipType;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "START_DATE", nullable = false, length = 7)
   public Date getStartDate() {
      return this.startDate;
   }

   public void setStartDate(Date startDate) {
      this.startDate = startDate;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "END_DATE", length = 7)
   public Date getEndDate() {
      return this.endDate;
   }

   public void setEndDate(Date endDate) {
      this.endDate = endDate;
   }

   @Column(name = "ACTIVE_IND", nullable = false, length = 1)
   public String getActiveInd() {
      return this.activeInd;
   }

   public void setActiveInd(String activeInd) {
      this.activeInd = activeInd;
   }

   @Column(name = "UPDATE_USER", nullable = false, length = 20)
   public String getUpdateUser() {
      return this.updateUser;
   }

   public void setUpdateUser(String updateUser) {
      this.updateUser = updateUser;
   }

   @Temporal(TemporalType.DATE)
   @Column(name = "UPDATE_DATE", nullable = false, length = 7)
   public Date getUpdateDate() {
      return this.updateDate;
   }

   public void setUpdateDate(Date updateDate) {
      this.updateDate = updateDate;
   }

   @Column(name = "SOURCE_ID", precision = 22, scale = 0)
   public BigDecimal getSourceId() {
      return this.sourceId;
   }

   public void setSourceId(BigDecimal sourceId) {
      this.sourceId = sourceId;
   }

   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "relationshipByRelationshipId")
   public Set<RelationshipRole> getRelationshipRolesForRelationshipId() {
      return this.relationshipRolesForRelationshipId;
   }

   public void setRelationshipRolesForRelationshipId(
         Set<RelationshipRole> relationshipRolesForRelationshipId) {
      this.relationshipRolesForRelationshipId = relationshipRolesForRelationshipId;
   }

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "relationshipByRelatedRelationshipId")
   public Set<RelationshipRole> getRelationshipRolesForRelatedRelationshipId() {
      return this.relationshipRolesForRelatedRelationshipId;
   }

   public void setRelationshipRolesForRelatedRelationshipId(
         Set<RelationshipRole> relationshipRolesForRelatedRelationshipId) {
      this.relationshipRolesForRelatedRelationshipId = relationshipRolesForRelatedRelationshipId;
   }

   @OneToMany(fetch = FetchType.LAZY, mappedBy = "relationship")
   public Set<Permission> getPermissions() {
      return this.permissions;
   }

   public void setPermissions(Set<Permission> permissions) {
      this.permissions = permissions;
   }
   
   @OneToMany(fetch = FetchType.LAZY, mappedBy = "relationship")
   public Set<EvidenceSource> getEvidenceSources() {
      return this.evidenceSources;
   }

   public void setEvidenceSources(Set<EvidenceSource> evidenceSources) {
      this.evidenceSources = evidenceSources;
   }
   
   @Column(name = "RELATIONSHIP_STATUS_ID")
   public Long getRelationshipStatusId() {
      return relationshipStatusId;
   }

   public void setRelationshipStatusId(Long relationshipStatusId) {
      this.relationshipStatusId = relationshipStatusId;
   }

   

}



Last edited by titan on Wed Apr 16, 2014 2:27 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Wed Apr 16, 2014 2:09 am 
Newbie

Joined: Sat Apr 12, 2014 9:02 am
Posts: 4
Hi,
I am getting exception(s) when I am executing the final Detached Criteria:


Apr 16, 2014 11:37:47 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000424:Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException Apr 16, 2014 11:37:47 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
Apr 16, 2014 11:37:47 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
Exception in thread "main" java.lang.NullPointerException at org.hibernate.loader.criteria.CriteriaQueryTranslator.getProjectedTypes(CriteriaQueryTranslator.java:401)
at org.hibernate.criterion.SubqueryExpression.createAndSetInnerQuery(SubqueryExpression.java:152)
at org.hibernate.criterion.SubqueryExpression.toSqlString(SubqueryExpression.java:68)
at org.hibernate.loader.criteria.CriteriaQueryTranslator.getWhereCondition(CriteriaQueryTranslator.java:419)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:110)
at org.hibernate.loader.criteria.CriteriaJoinWalker.<init>(CriteriaJoinWalker.java:92)
at org.hibernate.loader.criteria.CriteriaLoader.<init>(CriteriaLoader.java:93)
at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1516)
at org.hibernate.internal.CriteriaImpl.list(CriteriaImpl.java:374)
at Test.main(Test.java:149)


Top
 Profile  
 
 Post subject: Re: Native SQL Query to Hibernate Query using Criteria
PostPosted: Wed May 21, 2014 5:39 pm 
Newbie

Joined: Thu Mar 28, 2013 11:06 am
Posts: 8
hi,

the first one you can suppress with:

hibernate.jdbc.lob.non_contextual_creation=true

Best regards


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

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.