Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

question about entity PK

 
vitesse wei
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
  • 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?
 
Adam Tkaczyk
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic