[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-4263) @ManyToMany and @Index

Sindri Traustason (JIRA) noreply at atlassian.com
Wed Dec 22 09:02:05 EST 2010


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-4263?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=39419#action_39419 ] 

Sindri Traustason commented on HHH-4263:
----------------------------------------

While it's not a big issue for @ManyToMany it's worse when you have a one way @OneToMany association where the target entity is unaware of the association. This creates a join table where the PK is just the column with the target entities id. The other column is just a foreign key and is not indexed, and there is no way to define a index on it using annotations.

> @ManyToMany and @Index
> ----------------------
>
>                 Key: HHH-4263
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-4263
>             Project: Hibernate Core
>          Issue Type: Bug
>          Components: annotations
>         Environment: Windows Vista
> java version "1.5.0_11"
> Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
> Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode)
>            Reporter: Peter K. Guldbæk
>
> I have trouble adding an index to a column of a table which is part of a many-to-many property mapping. The following example causes a NullPointerException when generating the DDL (the exception can be seen at the end of my post):
> @Entity @Table(name="usr")
> public class User implements Serializable
> {
>     @Id @GeneratedValue(strategy=GenerationType.AUTO)
>     public Integer id;
>    
>     @ManyToMany(targetEntity=Target.class, cascade={})
>     @Index(name="fkey_usr_target", columnNames="usr_id")
>     @JoinTable(name="usr_target",
>         joinColumns=@JoinColumn(name="usr_id"),
>         inverseJoinColumns=@JoinColumn(name="target_id"))
>     public Collection<Target> targets;
> }
> @Entity @Table(name="target")
> public class Target implements Serializable
> {
>     @Id @GeneratedValue(strategy=GenerationType.AUTO)
>     public Integer id;
>    
>     @Basic
>     public String myValue;
> }
> NullPointerException thrown when an @Index annotation is used with a @ManyToMany:
> java.lang.NullPointerException
>         at org.hibernate.cfg.AnnotationBinder.processElementAnnotations(AnnotationBinder.java:1594)
>         at org.hibernate.cfg.AnnotationBinder.bindClass(AnnotationBinder.java:733)
>         at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:498)
>         at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:277)
>         at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1115)
>         at org.hibernate.tool.ant.ConfigurationTask.getConfiguration(ConfigurationTask.java:56)
>         at org.hibernate.tool.ant.HibernateToolTask.getConfiguration(HibernateToolTask.java:299)
>         at org.hibernate.tool.ant.Hbm2DDLExporterTask.execute(Hbm2DDLExporterTask.java:45)
>         at org.hibernate.tool.ant.HibernateToolTask.execute(HibernateToolTask.java:183)
>         at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
>         at sun.reflect.GeneratedMethodAccessor19.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
>         at java.lang.reflect.Method.invoke(Method.java:585)
>         at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
>         at org.apache.tools.ant.Task.perform(Task.java:348)
>         at org.apache.tools.ant.Target.execute(Target.java:357)
>         at org.apache.tools.ant.Target.performTasks(Target.java:385)
>         at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
>         at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
>         at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
>         at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
>         at org.apache.tools.ant.Main.runBuild(Main.java:698)
>         at org.apache.tools.ant.Main.startAnt(Main.java:199)
>         at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
>         at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

       



More information about the hibernate-issues mailing list