Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid composite primary key specification

 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to deploy a web module to Sun Java System Application Server Platform Edition 9.0_01 (JRE 1.5.0_12) and I get the following exception:

Exception Description: Invalid composite primary key specification. The names of the primary key fields or properites in the primary key class [edu.ldsbc.payroll.model.TimeEntryId] and those of the entity bean class [class edu.ldsbc.payroll.model.TimeEntry] must correspond and their types must be the same. Also, ensure that you have specified id elements for the corresponding attributes in XML and/or an @Id on the corresponding fields or properties of the entity class.

Here are the two classes:



 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you want a composite primary key, the annotations to use are @EmbeddedId
and @IdClass.
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case I'm using the @IdClass annotation which I understand only requires a @IdClass annotation on the entity class while the id class just needs to implement serializable and define a few methods that hibernate uses.

I tried deploying this app to tomcat and it thinks it just fine (actually I think tomcat is just being more forgiving). Is there a Best Practices standard that I'm violating here?
 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Matthew Snow:
In this case I'm using the @IdClass annotation which I understand only requires a @IdClass annotation on the entity class while the id class just needs to implement serializable and define a few methods that hibernate uses.[/QUOTE
Your entity code looks correct enough. This looks like a bug in the persistence provider. I have no idea what you mean by "few methods that Hibernate uses" though. If you are using the Sun app server aren't you using the TopLink Essentials persistence provider?
I tried deploying this app to tomcat and it thinks it just fine (actually I think tomcat is just being more forgiving). Is there a Best Practices standard that I'm violating here?
Well, the annotations on the PK class are not going to be used and should not really be there. You can start by removing those.
 
Edvins Reisons
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just looked up that the specification allows to use an @IdClass with @Id on the entity properties . Still, it is a duplication of code (the property definitions), and, especially if you encounter problems with it, an @EmbeddedId within the entity class appears easier.
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed all my composite primary key definitions from @ClassId annotations to @EmbeddedId annotations and I am now able to deploy my web module.

I have now, however, encountered another error that's more vague when I try to Enable the web module after I've deployed it. It's a big ugly exception saying it could not create inner bean 'transactionInterceptor' due to error creating bean 'transactionManager' due to error creating bean 'entityManagerFactory'. This is all caused by the following exception:

Caused by: org.hibernate.MappingException: Could not determine type for: oracle.toplink.essentials.indirection.ValueHolderInterface, for columns: [org.hibernate.mapping.Column(_toplink_personalData_vh)]

Here is the code for entity PersonalData:

 
Mike Keith
author
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks like you are deploying the entities using TopLink Essentials but then trying to use a Hibernate provider with them. That's not going to work because they do different things to the class at runtime. Hibernate generates an extra modified proxy class for it while TopLink weaves it directly.

BTW, you should not put the @Basic annotation on your relationship as it will typically get ignored in the best case and in the worst case be an error. Use the fetch attribute in the @ManyToOne/@OneToOne annotations.
 
Matthew Snow
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, you are right. Sun App Server uses TopLink Essentials by default when verifying a WAR durring deploy, and according to documentation I can't change that. I can however disable verifiction when I deploy and I can define a separate persistence providor for the module to run under after it's deployed. Apparently this is done by copying the necesary jar files to the lib directory of the domain that it's installed to. However I'm still getting the same error. Since this is a server problem, I'm continuing this post under forum "Other Java Products and Servers" and topic "Sun App Server PE 9 and Hibernate".
 
Tom Tomm
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After 5 years the bug is still here !!!

My id class:
Integer origID;
String informationAI;

and my normal class
@Transient
private static final long serialVersionUID = 1L;
//@EmbeddedId
//protected origID origID;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "origID")
private Integer origID;
@Id
//@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "informationAI")
private String informationAI;

and before you ask, yes I tried commenting out unnecessary lines/various lines.

The types ARE the same, yet the java says THEY ARE NOT

After 3 hours I am going crazy now.... Somone help please....


---------------
edit solved. I won't tell you how, because no one wanted to help me in first place.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic