• 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
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!