persistence@glassfish.java.net

Re: using generated value with a non Id field

From: James Sutherland <jamesssss_at_yahoo.com>
Date: Thu, 20 Sep 2007 06:24:52 -0700 (PDT)

Sorry you are correct, TopLink Essentials is currently only processing the
@GeneratedValue for the id. Please log an enhancment request to have it
processed for any basic mapping. This would be functionality beyond the JPA
spec, but TopLink Essentials already supports this, it is just not hooked up
to the annotation.

As a workaround you can enable this using the TopLink Essentials descriptor
API. Specify a DescriptorCustomizer in your persistence.xml.

public class MyDescriptorCustomizer implements DescriptorCustomizer {
  public void customize(ClassDescriptor descriptor) {
    descriptor.setSequenceNumberName("OWNER_SEQ");
    descriptor.setSequenceNumberFieldName("number");
  }
}

---
http://wiki.java.net/bin/view/People/JamesSutherland James Sutherland 
dknotts wrote:
> 
> I'm having the same problem.  I tried what you suggested, but it isn't
> working.  All the documentation I have read says that @GeneratedValue only
> works in conjunction with the @Id annotation, and this is exactly how my
> program is reacting.  I added a copy of the class where I am trying to
> accomplish this below.  Can you give me some pointers on what I'm doing
> wrong, please?
> 
> @Entity
> @Table(name = "Owner")
> public class Owner {
> 	@Id
> 	@Column(name = "sysId")
> 	private String sysId;
> 
> 	@GeneratedValue(strategy = GenerationType.IDENTITY)
> 	@Column(name = "number")
> 	private int number;
> 
> 	public Owner() {		
> 	}
> 
> 	public String getSysId() {
> 		return sysId;
> 	}
> 
> 	public int getNumber() {
> 		return number;
> 	}
> }
> 
> 
> James Sutherland wrote:
>> 
>> Yes, just annotate the field with @GeneratedValue.  However in
>> TopLink-Essentials you can only generate a sequence value for one field
>> in the class, it does not need to be the id, but only one field is
>> supported.
>> 
>> 
>> sud-3 wrote:
>>> 
>>> Is it possible to have JPA (toplink-essentials) auto-generate a column
>>> value for a non Id field?
>>> 
>> 
>> 
> 
> 
-- 
View this message in context: http://www.nabble.com/using-generated-value-with-a-non-Id-field-tf4339169.html#a12797022
Sent from the java.net - glassfish persistence mailing list archive at Nabble.com.