-->
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.  [ 4 posts ] 
Author Message
 Post subject: GenericGenerator in composite key class not working
PostPosted: Thu Jun 03, 2010 5:17 pm 
Newbie

Joined: Thu Jun 03, 2010 5:02 pm
Posts: 5
Hi,
I have a java class of the composite key.
Code:

@Embeddable
public class RmInformationItemPK implements Serializable
{   
  private static final long serialVersionUID = 1L;
 
  @Column(name = "information_item_id")
  @GenericGenerator(name = "IdSeq", strategy = "com.kelman.hibernate.VarcharSequenceGenerator",
      parameters = { @Parameter(name = "sequence", value = "K_INFORMATION_ITEM_ID_SEQ") })
  @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "IdSeq")
  private String informationItemId;   

  @Column(name = "info_item_type")
  private String infoItemType; 
   
  public String getInformationItemId()
  {
   return informationItemId;
  }
   
  public void setInformationItemId(String informationItemId)
  {
   this.informationItemId = informationItemId;
  }

  public String getInfoItemType()
  {
   return infoItemType;
  }

  public void setInfoItemType(String infoItemType)
  {
   this.infoItemType = infoItemType;
  }

  @Override
  public int hashCode()
  {
    return new HashCodeBuilder().append(getInformationItemId())
                                  .append(getInfoItemType()).toHashCode();
  }   
 
  @Override
  public boolean equals(Object obj)
  {
   if ( !(obj instanceof RmInformationItemPK) ) return false;
   RmInformationItemPK castOther = (RmInformationItemPK)obj;
   return new EqualsBuilder().append(this.getInformationItemId(), castOther.getInformationItemId())
                              .append(this.getInfoItemType(), castOther.getInfoItemType())                         
                              .isEquals(); 
  }
}

The composite key is called in the object class:
Code:
public class RmInformationItem implements Serializable
{
  private static final long serialVersionUID = 1L;
  @Id
  private RmInformationItemPK pk;
}

When I create an instance of this object, I did:
Code:
RmInformationItemPK infoItemPK = new RmInformationItemPK();
infoItemPK.setInfoItemType("SEIS_TRACE");
RmInformationItem info = new RmInformationItem();
info.setPk(infoItemPK);
session.save(info);

I found that the GenericGenerator didn't get called so that the field "informationItemId" in the class RmInformationItemPK.java has no value.
How to apply the GenericGenerator in a composite key class?

Thanks,


Top
 Profile  
 
 Post subject: Re: GenericGenerator in composite key class not working
PostPosted: Fri Jun 04, 2010 2:37 am 
Expert
Expert

Joined: Wed Mar 03, 2004 6:35 am
Posts: 1240
Location: Lund, Sweden
I think composite keys always have to be assigned by the application. This is mentioned in the documentation: http://docs.jboss.org/hibernate/stable/ ... ompositeid


Top
 Profile  
 
 Post subject: Re: GenericGenerator in composite key class not working
PostPosted: Fri Jun 04, 2010 10:33 am 
Newbie

Joined: Thu Jun 03, 2010 5:02 pm
Posts: 5
Thanks for replying. I just found that hibernate 3.5.2 might have resolved this issue but when I tried it I got another error:
Code:
org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String
at org.hibernate.id.IdentifierGeneratorHelper.getIntegralDataTypeHolder(IdentifierGeneratorHelper.java:178)
        at org.hibernate.id.SequenceGenerator.buildHolder(SequenceGenerator.java:142)
        at org.hibernate.id.SequenceGenerator.generateHolder(SequenceGenerator.java:115)
        at org.hibernate.id.SequenceGenerator.generate(SequenceGenerator.java:105)

The attribute type in my class is String as the type of this field in our database is VARCHAR2. Hibernate 3.2.5 doesn't have this problem.
Does any one know how to fix it?

Thanks,


Top
 Profile  
 
 Post subject: Re: GenericGenerator in composite key class not working
PostPosted: Fri Sep 17, 2010 9:52 am 
Newbie

Joined: Fri Sep 17, 2010 9:47 am
Posts: 1
Hello

I'm new with hibernate and I have a similar problem as yours... Can you explain me please how did you solve it?

Thank you!


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