[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4261) @Any mapping fails during configuration: "@Any requires an explicit @JoinColumn(s)"
Xavier Dury (JIRA)
noreply at atlassian.com
Fri Feb 10 08:59:10 EST 2012
[ https://hibernate.onjira.com/browse/HHH-4261?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=45488#comment-45488 ]
Xavier Dury commented on HHH-4261:
----------------------------------
Tested with hibernate 4.0.1
If META-INF/orm.xml is present on the classpath => org.hibernate.AnnotationException: @Any requires an explicit @JoinColumn(s): org.hibernate.issues.any.Attachment.container
After removing META-INF/orm.xml => org.hibernate.MappingException: Foreign key (FK1C93543ED11F13A:Attachment [container_type,container_id])) must have same number of columns as the referenced primary key (Issue [id])
Now, I admit my setup/mapping can be incorrect due to the fact that I can't find anything in hibernate documentation wrt to bidirectionnal associations using @Any.
I would like to implement something like:
class Attachment {
@ManyToOneAny?
@AnyMetaDef(...)
@JoinColumn
Container container;
}
class Blog implements Container {
@OneAnyToMany?(mappedBy = "container")
Set<Attachment> attachments;
}
class Issue implements Container {
@OneAnyToMany?(mappedBy = "container")
Set<Attachment> attachments;
}
I found this in hibernate doc (http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html/entity.html#d0e3238)
@ManyToAny(metaColumn = @Column(name = "property_type"))
@AnyMetaDef(idType = "integer", metaType = "string", metaValues = {
@MetaValue(value = "S", targetEntity = StringProperty.class),
@MetaValue(value = "I", targetEntity = IntegerProperty.class)})
@JoinTable(name = "obj_properties", joinColumns = @JoinColumn(name = "obj_id"), inverseJoinColumns = @JoinColumn(name = "property_id"))
List<Property> getGeneralProperties()
which I think is very confusing
because @ManyToOne is typically used to indicate a (* -> 1) association
and @ManyToAny is used to denote a (1 -> *) association where * could be anything
> @Any mapping fails during configuration: "@Any requires an explicit @JoinColumn(s)"
> -----------------------------------------------------------------------------------
>
> Key: HHH-4261
> URL: https://hibernate.onjira.com/browse/HHH-4261
> Project: Hibernate ORM
> Issue Type: Bug
> Components: annotations
> Environment: Hibernate core 3.2.4.sp1 (reported in 3.3.1.GA as well)
> Hibernate annotations 3.3.1.GA (reported in 3.4.0.GA as well)
> Hibernate entity manager 3.3.1.ga
> MySQL 5.0.45
> Reporter: Noah Miller
> Attachments: hibernate-issues-any.zip
>
>
> When I try to apply the @Any annotation, I get the following exception:
> ERROR [org.jboss.kernel.plugins.dependency.AbstractKernelController] Error installing to Start: name=persistence.units:jar=test-build.jar,unitName=blueserve state=Create
> org.hibernate.AnnotationException: @Any requires an explicit @JoinColumn(s): com.builderadius.blueserve.model.Note.noteOwner
> at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1201)
> at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:739)
> at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:501)
> at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:282)
> at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
> at org.hibernate.ejb.Ejb3Configuration.buildMappings(Ejb3Configuration.java:1195)
> at org.hibernate.ejb.EventListenerConfigurator.configure(EventListenerConfigurator.java:149)
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:814)
> at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:412)
> at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:126)
> at org.jboss.ejb3.entity.PersistenceUnitDeployment.start(PersistenceUnitDeployment.java:259)
> See the forum posting http://forum.hibernate.org/viewtopic.php?p=2403045 for another description of this problem. That thread suggests the problem is with EJB3OverridenAnnotationReader not adding properties annotated with @JoinColumn if xml mapping files exist.
> My code is:
> @Any(metaColumn = @Column(name = "RelatedRecType"))
> @AnyMetaDef(idType = "integer", metaType = "string", metaValues = {
> @MetaValue(targetEntity = Approval.class, value = "approval"),
> @MetaValue(targetEntity = ZoningPermit.class, value = "zoningpermit") })
> @JoinColumn(name = "RelatedRecNum", nullable = false)
> public BlueserveEntity getNoteOwner()
> {
> return this.noteOwner;
> }
> An orm.xml file (auto-generated by seam-gen) exists in this project, though it has no entity mappings and there are no other hbm.xml files. When I remove this file, I no longer receive the exception (that's not a long-term solution).
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the hibernate-issues
mailing list