-->
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.  [ 6 posts ] 
Author Message
 Post subject: Getting Property Names of Composite Primary Keys
PostPosted: Tue Aug 05, 2008 2:12 pm 
Newbie

Joined: Fri Jul 11, 2008 9:37 am
Posts: 6
I need to be able to access the column names of the properties of my composite key. I am able to retrieve the rest of the attributes of my entity through the ClassMetadata class using getPropertyNames(). However, it does not give me everything. Anyone know how to do this?

Tiki


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 05, 2008 3:27 pm 
Newbie

Joined: Fri Jul 11, 2008 9:37 am
Posts: 6
If I need to further explain my situation or provide code samples to clarify things just ask.

Tiki


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 11, 2008 3:41 pm 
Newbie

Joined: Fri Jul 11, 2008 9:37 am
Posts: 6
Since no one has posted im going to assume I wasnt clear. Here is my entity and PK classes.

Code:
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.Table;
import javax.portlet.ActionRequest;
import com.burris.ssapp.common.Input;


@Entity
@Table( name = "Items")
@IdClass( ItemPK.class )
public class Item {

   // Primary key
   private String supplierID;
   private String caseGTIN;
   
   // Other Database properties
   ...
   
   public Item() {
      
   }
   
   
   /**
    * Getters
    */
   
   @Id
   @Column( name = "SupplierID" )
   public String getSupplierID() {
      
      return this.supplierID;
   }
   
   @Id
   @Column( name = "CaseGTIN" )
   public String getCaseGTIN() {
      
      return this.caseGTIN;
   }

   // Other getters and setters
   ...
}

----------------------------------------------------------------------------------

import java.io.Serializable;
import javax.persistence.Embeddable;


@Embeddable
public class ItemPK implements Serializable {
   
   private static final long serialVersionUID = 9816235861478365L;
   private String supplierID;
   private String caseGTIN;
   
   public String getSupplierID() {
   
      return this.supplierID;
   }

   public String getCaseGTIN() {
   
      return this.caseGTIN;
   }
   
   public void setSupplierID( String supplierID ) {
   
      this.supplierID = supplierID;
   }
   
   public void setCaseGTIN( String caseGTIN ) {
   
      this.caseGTIN = caseGTIN;
   }
   
   public boolean equals( Object obj ) {
      
      // equals implementation
   }
   
   public int hashCode() {
      
           // hashCode implementation
   }
}



I think I have annotated them correctly, however, the primary key data does not show up in the ClassMetadata class. Heres what I get for the metadata:

Code:
[0]   "_identifierMapper"   
[1]   "length"   
[2]   "status"   
[3]   "itemName"   
[4]   "width"   
[5]   "height"   
[6]   "itemDescription"   
[7]   "warehouseLocation"   
[8]   "storageAccount"   
[9]   "itemUOM"   
[10]   "brand"   
[11]   "itemClass"   
[12]   "owned"   
[13]   "packagePack"   
[14]   "packageSizeDescription"   
[15]   "packageUOM"   
[16]   "packageGTIN"   
[17]   "casePack"   
[18]   "caseSizeDescription"   
[19]   "caseUOM"   
[20]   "netWeight"   
[21]   "tare"   
[22]   "grossWeight"   
[23]   "weightUOM"   
[24]   "cube"   
[25]   "cubeUOM"   
[26]   "casesPerLayer"   
[27]   "layersPerPallet"   
[28]   "POUOM"   
[29]   "guaranteedSale"   
[30]   "freightAmount"   
[31]   "freightPercent"   
[32]   "freightUOM"   
[33]   "price"   


Notice how CaseGTIN and SupplierID are missing. Any thoughts on how to gain access to these? I have tried the getIdentifierPropertyName() but it returns null. Im not sure if there is anything I can do with the Identifier mapper.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 9:53 am 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
I am also looking to solve same problem.. anyone ? thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 25, 2008 7:18 pm 
Pro
Pro

Joined: Tue Aug 26, 2003 8:07 pm
Posts: 229
Location: Brisbane, Australia
Code:
Property idProp = PersistentClass.getIdentitiferProperty()


will give you the identifier property.

Try casting the result of calling Property.getType() to a "ComponentType", then using the ComponentType.getPropertyNames() method.

Don't know if it will work for you, but that was the only way I could figure out how to access the properties of an (non-id) @Embeddable component that I was using - maybe it will work for you.

_________________
Cheers,
Shorn.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 26, 2008 2:31 pm 
Newbie

Joined: Mon Aug 25, 2008 8:39 am
Posts: 10
Thanks for the reply.

I got the information using ClassMetadata

getIdentifierPropertyName();.

or use getNaturalIdentifierProperties() .. if entity has natural ids hasNaturalIdentifier().


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.