• 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:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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
 
Amateurs built google. Professionals built the titanic. We can't find the guy that built this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic