openjpa-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zbynek Vavros <>
Subject Composite key problem
Date Mon, 13 Aug 2012 05:38:46 GMT


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
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 :

@Table(name = "admin_skills")
public class DitaAdminSkill {

	private DitaAdminSkillPK id;

	@Column(name = "skill")
	private Integer skill;

	//getters & setters

public class DitaAdminSkillPK implements Serializable{

	@JoinColumn(name = "admin_id")
	private DitaAdmin admin;

	@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",
	DitaAdminSkillDao dispDao = applicationContext.getBean
	List<DitaAdminSkill> disp = dispDao.findAll();

But when I try to run this with OpenJPA I get an error : Unknown column
'' 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 -->

Thanks !!!!

View raw message