• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

question about entity PK

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
question:
Which example of Java Persistence identity definitions is portable and correct assuming NO mapping descriptor is present?

A. @Entity public class A {
@ld private float id;
// more code here
}
B. @ldClass(com.acme.LineltemPK.class)
@Entity
public class Lineltem {
@ld int orderld;
@ld int lineltemld;
// more code here
}
C. @Entity public class Project {
@ld @GeneratedValue(strategy=TABLE)
public String getProjectld() {return pid;}
// more code here
}
D. @Entity
public class Employee {
@ld public java.util.Date getBirthday() {return bday;}
// more code here
}

given answer is B,but why C is wrong?
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
C is wrong because of generated primary key. In this case only integral types (byte, short, int and long) will be portable.

For further information see JSR 220 - Java Persistence API, page 22, passage 2.1.4
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic