Did you try GenerationType.IDENTITY ? @GeneratedValue(strategy = GenerationType.IDENTITY)
I think it should work with int but I prefer long instead. On Sep 8, 2009, at 10:56 , B.L. Zeebub wrote:
Hi I have attached my entity definition below. This was created over a pre-existing database. I create the EntityManagerFactory to obtain the entitymanager (em) as normal and execute the code; String jpql = "select c from Platform c"; em.getTransaction().begin(); entities = (List) em.createQuery(jpql).getResultList(); em.getTransaction().commit();I get the list of Platform entities as expected. Looping through the list, getPlatformName() returns the text as expected, but getId() always returns 0(zero) for all members of the list. Any ideas as to what I've missed. Regards @Entity @Table(name="Platform") public class Platform implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(strategy=GenerationType.AUTO) @Column(name="id", unique=true, nullable=false) private int id; @Column(name="PlatformName", length=32) private String platformName; //bi-directional many-to-one association to PEcu @OneToMany(mappedBy="platform") private Set<PEcu> pecus; public Platform() { } public int getId() { //TODO: Remove System.out.println("Platform.getId() called - " + this.id); return this.id; } public void setId(int id) { this.id = id; } public String getPlatformName() { //TODO: Remove System.out.println("Platform.getPlatform() called - " + this.platformName); return this.platformName; } public void setPlatformName(String platformName) { this.platformName = platformName; } public Set<PEcu> getPecus() { return this.pecus; } public void setPecus(Set<PEcu> pecus) { this.pecus = pecus; } } -- View this message in context: http://n2.nabble.com/NEWBIE-OpenJPA-Cannot-get-id-field-returned-tp3601995p3601995.html Sent from the OpenJPA Users mailing list archive at Nabble.com.
