Problem with JPA , persistence.xml and Inner Classes.

I have a persistence.xml with multiple persistence units, so i manually define the entities that i want to associate with each persistence unit. No problem with that.

Now, i have a lot of entities in which i need to have composite keys, so i add an Inner Class to the Entity, that i need a composite key, defining the composite key.

Problem is that if i use true, IDEA wont recognize the Inner Classes composite keys, and gives me inspection errors and the ER Diagram does not show properly those classes. It is something i am doing wrong? Or is actually an IDEA problem? Edit: If i add the inner class to persistence.xml all works fine in idea, like: com.somepackage.class.innerclass]]>

but then hibernate cant find that class, and gives an error mapping the entities, so it does not work.

Message was edited by:
Roberto Cortez

Message was edited by:
Roberto Cortez

2 comments

Hello Roberto,

How does your code look and what errors IDEA gives you?
(screenshots and code-samples are welcome)


Regards,
Gregory Shrago

Roberto Cortez wrote:

I have a persistence.xml with multiple persistence units, so i
manually define the entities that i want to associate with each
persistence unit. No problem with that.

Now, i have a lot of entities in which i need to have composite keys,
so i add an Inner Class to the Entity, that i need a composite key,
defining the composite key.

Problem is that if i use
<exclude-unlisted-classes>true</exclude-unlisted-classes>, IDEA wont
recognize the Inner Classes composite keys, and gives me inspection
errors and the ER Diagram does not show properly those classes.

It is something i am doing wrong? Or is actually an IDEA problem?

0

I get this error:

@javax.persistence.EmbeddedId attribute type should be an Embeddable

A screenshot and a source file of the problem in attach

Thank you for your time

Edit:

This happens when i have <exclude-unlisted-classes>true</exclude-unlisted-classes> in my persistence.xml. If i remove it i get another inspection error, this time at the Embeddable class:

Persistent object class 'TestPK' should be a top-level class

Those inspectiong are really strange since its valid to have an Embeddable PK as an inner class, according to JPA... and i have no problems generating the ddl from those entites... at least hibernate does not complain about it and everything generates fine. Annoying that does not work in IDEA, since i have a persistence unit with a lot of composite keys, and for better organization i would like to have them inside the entities that need them. Also annoying that i cannot use the hql autocomplete because idea wont recognize the embeddable inner classes.

Message was edited by:
Roberto Cortez



Attachment(s):
Test.java
idea7_embeddableId_error.jpg
0

Please sign in to leave a comment.