One question, why your create statement doesnt have a primary key? El 13/08/2012 00:39, "Zbynek Vavros" <zbynek_vav...@cz.ibm.com> escribió:
> > Hi, > > Im having trouble with composite key and OpenJPA. > I was using hibernate so excuse my lack of OpenJPA knowledge. > > I have a table already created and one that I cannot modify : > > CREATE TABLE `admin_skills` ( > `admin_id` INT(11) NOT NULL, > `account_id` INT(11) NOT NULL, > `skill` INT(11) NOT NULL DEFAULT '5', > UNIQUE INDEX `account_id` (`account_id`, `admin_id`), > INDEX `admin_id` (`admin_id`), > CONSTRAINT `admin_skills_ibfk_1` FOREIGN KEY (`admin_id`) REFERENCES > `admins` (`idadmin`) ON UPDATE CASCADE ON DELETE CASCADE, > CONSTRAINT `admin_skills_ibfk_2` FOREIGN KEY (`account_id`) REFERENCES > `account` (`account_id`) ON UPDATE CASCADE ON DELETE CASCADE > ) > > I have created following entity/key : > > @Entity > @Table(name = "admin_skills") > public class DitaAdminSkill { > > @EmbeddedId > private DitaAdminSkillPK id; > > @Column(name = "skill") > private Integer skill; > > //getters & setters > > @Embeddable > public class DitaAdminSkillPK implements Serializable{ > > @ManyToOne > @JoinColumn(name = "admin_id") > private DitaAdmin admin; > > @ManyToOne > @JoinColumn(name = "account_id") > private DitaAccount account; > > //getters & setters > > This works just fine with Hibernate 4.1.4Final : > > ApplicationContext applicationContext = new > ClassPathXmlApplicationContext(new String[] {"applicationContext.xml", > "db_beans.xml"}); > DitaAdminSkillDao dispDao = applicationContext.getBean > (DitaAdminSkillDao.class); > List<DitaAdminSkill> disp = dispDao.findAll(); > System.out.println(disp.get(0).getId().getAccount()); > > > But when I try to run this with OpenJPA I get an error : Unknown column > 't0.id' in 'field list' > Seems like it is ignoring the @EmbeddedId annotation and tries to select > directly the ID, which do not exists. > I have been trying to use @IdClass instead but with pretty much same > result :( > > Since OpenJPA has general lack of support/forums/everything, I wasnt able > to find anything useful through google. > > If anyone has any comments, please, it will be more than welcomed. > > Oh, and I am using OpenJPA 2.1.5 with Maven (tried 2.2.0-SNAPSHOT but does > the same) : > > <!-- Apache implementation of JPA2.0 --> > <dependency> > <groupId>org.apache.openjpa</groupId> > <artifactId>openjpa-all</artifactId> > <version>2.1.5</version> > </dependency> > > Thanks !!!! > > >