Bug 197069 - Support for entities in Jars
Summary: Support for entities in Jars
Status: RESOLVED FIXED
Alias: None
Product: Dali JPA Tools
Classification: WebTools
Component: General (show other bugs)
Version: 1.0   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: 2.2 M7   Edit
Assignee: Brian Vosburgh CLA
QA Contact:
URL:
Whiteboard:
Keywords: plan
Depends on: 271561
Blocks: 243817
  Show dependency tree
 
Reported: 2007-07-18 23:29 EDT by Tom Mutdosch CLA
Modified: 2009-05-01 16:16 EDT (History)
7 users (show)

See Also:
neil.hauge: pmc_approved? (david_williams)
neil.hauge: pmc_approved? (raghunathan.srinivasan)
neil.hauge: pmc_approved? (naci.dai)
neil.hauge: pmc_approved? (deboer)
neil.hauge: pmc_approved+
neil.hauge: pmc_approved? (kaloyan)


Attachments
initial patch candidate (2.47 MB, patch)
2009-04-06 17:03 EDT, Brian Vosburgh CLA
no flags Details | Diff
another patch candidate (2.61 MB, patch)
2009-04-08 11:54 EDT, Brian Vosburgh CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Mutdosch CLA 2007-07-18 23:29:44 EDT
This is a request to have Dali support entities found in jars.  I guess I'm mainly referring to support in the model. It would be cool if the IJpaProject.jpaFiles() could find entities in the jar files as well (possibly modeled as a JavaJarEntity). This would be useful to use to find all entities available in a project.

Further details from Karen Moore from the dev-list:

Could you enter an enhancement request for this? We have discussed it as a possibility in our next release and would certainly like to be able to handle it, time allowing. There are 2 different use cases here, 1 being the case where the jar file has attached source. We would then be able to use the JDT for reading the annotations and include those files in our validation and possibly allow a read-only view onto those files in the JPA Structure and Details views. The other case is class files without source where we would not be able to use JDT to interogate and would have to rely on java annotation api. I don't know the difficulty of this, just something else we need to keep in mind.

thanks,
Karen

And a note from Max from the list:
Tip: org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader is useful in this regard - it reads raw .class files and give you access to the annotations.
Using attached source would be faulty IMO.
Comment 1 Neil Hauge CLA 2008-03-25 23:38:39 EDT
Unfortunately it doesn't look like this functionality is going to make it for 2.0. Retargeting for the next release.  This will be a top priority.
Comment 2 Neil Hauge CLA 2008-11-03 11:00:37 EST
This item was too large to fit in the 2.1 release.  We will continue working on this and now target for 2.2.
Comment 3 Shaun Smith CLA 2008-12-11 10:05:33 EST
Possible sources of binary classes that should be mappable:

* Classes in Required Projects
* Jars in EARS containing JPA project
* Jars in WEB-INF/Lib of JPA enabled Dynamic Web Projects
* Jars referenced directly on classpath (by JPA project or Required Project)
* Jars referenced through Libraries on Classpath (by JPA project or Required Project)
* Jars referenced through Variables on Classpath (by JPA project or Required Project)
* Jars referenced through "logical" libraries on Classpath (plugin dependencies)
Comment 4 Shaun Smith CLA 2008-12-11 10:34:30 EST
Possible sources of binary classes that should be mappable:

* Jars in EARS containing JPA project
* Jars in WEB-INF/Lib of JPA enabled Dynamic Web Projects
* Classes in Required Projects
* Classes in Projects that will be jar'd at deployment either into EAR or WEB-INF/lib
* Jars referenced directly on classpath (by JPA project or Required Project)
* Jars referenced through Libraries on Classpath (by JPA project or Required
Project)
* Jars referenced through Variables on Classpath (by JPA project or Required
Project)
* Jars referenced through "logical" libraries on Classpath (plugin
dependencies)
Comment 5 Neil Hauge CLA 2009-03-05 15:10:27 EST
Re-targeting for M7 as a feature freeze exception.  It doesn't appear that we will be able to complete this feature for M6, and as such, I would like to have it go in as an exception in M7.  

This feature has been planned for a long time, and has been requested by adopters and end-users.  Requesting PMC approval.
Comment 6 Brian Vosburgh CLA 2009-04-06 17:03:40 EDT
Created attachment 131058 [details]
initial patch candidate

Large patch with model changes to support binary entities etc. All pre-existing JUnit tests pass without a problem; but there are no new tests for this stuff yet. Very lightly tested....
Comment 7 Karen Butzke CLA 2009-04-07 10:45:14 EDT
Brian, I have a ManyToOne annotation in my jar file, I get this exception when building up the project:

org.eclipse.core.internal.resources.ResourceException(/Bar)[566]: java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [Ljava.lang.String;
    at org.eclipse.jpt.core.internal.resource.java.binary.BinaryRelationshipMappingAnnotation.buildCascadeTypes(BinaryRelationshipMappingAnnotation.java:128)
    at org.eclipse.jpt.core.internal.resource.java.binary.BinaryRelationshipMappingAnnotation.<init>(BinaryRelationshipMappingAnnotation.java:45)
    at org.eclipse.jpt.core.internal.resource.java.binary.BinaryManyToOneAnnotation.<init>(BinaryManyToOneAnnotation.java:30)
    at org.eclipse.jpt.core.internal.resource.java.ManyToOneAnnotationDefinition.buildAnnotation(ManyToOneAnnotationDefinition.java:55)
    at org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider.buildAttributeMappingAnnotation(GenericJpaAnnotationProvider.java:145)
Comment 8 Karen Butzke CLA 2009-04-07 11:19:15 EDT
SecondaryTables does not work when in a jar. I defined an Entity with these annotations, exported to a jar and referenced that jar in another JPA project.  The exception below occurred when building the project.  AttributeOverrides and QueryHints in a NamedQuery also cause the same problem.

@Entity
@SecondaryTables({@SecondaryTable(name = "FOO"),@SecondaryTable(name = "BAR")})

Java Model Exception: Java Model Status [@javax.persistence.SecondaryTable [in @javax.persistence.SecondaryTables [in Employee [in Employee.class [in model [in lib/myJPA.jar [in Bar]]]]]] does not exist]
	at org.eclipse.jdt.internal.core.JavaElement.newNotPresentException(JavaElement.java:492)
	at org.eclipse.jdt.internal.core.JavaElement.openWhenClosed(JavaElement.java:526)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:252)
	at org.eclipse.jdt.internal.core.JavaElement.getElementInfo(JavaElement.java:238)
	at org.eclipse.jdt.internal.core.Annotation.getMemberValuePairs(Annotation.java:57)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation.getJdtMemberValuePairs(BinaryAnnotation.java:69)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation.getJdtMemberValuePair(BinaryAnnotation.java:59)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryAnnotation.getJdtMemberValue(BinaryAnnotation.java:51)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryBaseTableAnnotation.buildName(BinaryBaseTableAnnotation.java:79)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryBaseTableAnnotation.<init>(BinaryBaseTableAnnotation.java:40)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinarySecondaryTableAnnotation.<init>(BinarySecondaryTableAnnotation.java:32)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinarySecondaryTablesAnnotation.buildSecondaryTables(BinarySecondaryTablesAnnotation.java:53)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinarySecondaryTablesAnnotation.<init>(BinarySecondaryTablesAnnotation.java:34)
	at org.eclipse.jpt.core.internal.resource.java.SecondaryTablesAnnotationDefinition.buildAnnotation(SecondaryTablesAnnotationDefinition.java:54)
	at org.eclipse.jpt.core.internal.platform.GenericJpaAnnotationProvider.buildTypeSupportingAnnotation(GenericJpaAnnotationProvider.java:106)
	at org.eclipse.jpt.core.internal.resource.java.binary.BinaryPersistentType.buildSupportingAnnotation(BinaryPersistentType.java:112)
Comment 9 Karen Butzke CLA 2009-04-07 11:29:09 EDT
Same problem with org.eclipse.persistence.annotations.ObjectTypeConverter conversionValues

@ObjectTypeConverter(name = "po", dataType = String.class, objectType = String.class, conversionValues = @ConversionValue(dataValue = "M", objectValue = "Male"))
Comment 10 Brian Vosburgh CLA 2009-04-08 11:54:47 EDT
Created attachment 131307 [details]
another patch candidate

Fix the problem with CascadeTypes.
Comment 11 Brian Vosburgh CLA 2009-04-08 17:40:21 EDT
I have checked in the latest patch. There are still a few problems with nested annotations; but those will be fixed once JDT bug 271561 is fixed. (We have already tested with the latest patch attached to that bug and things work fine.) As a result, until we are running on the fixed JDT code, mapping classes in a referenced JAR in the current project's orm.xml should work fine; but Dali will not be able to read many of the JPA annotations that might be already existing in the JAR.
Comment 12 Olivier Thomann CLA 2009-04-16 12:03:00 EDT
The bug 271561 is now fixed.
Let me know if you still have issue with this bug.
Comment 13 Paul Fullbright CLA 2009-04-23 15:25:43 EDT
Jar file support has been added to the UI in the following ways:
- jar file references show up in the persistence.xml structure view
- jar files (that resolve) show up in the project explorer
- the persistence.xml editor allows users to add/remove jar files
- basic validation has been added for jar file references (jar files specified are not duplicates, and they resolve to actual jar files)
Comment 14 Neil Hauge CLA 2009-05-01 16:16:05 EDT
I'm marking this bug as resolved for M7 as the JDT fixes have been confirmed and the necessary UI has been completed.  Please file additional bugs for any remaining issues related to this feature.