-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: @ManyToMany and @Index
PostPosted: Thu Jun 28, 2007 4:01 am 
Newbie

Joined: Thu Jun 28, 2007 3:35 am
Posts: 1
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):

Code:
@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;
}


It is quite possible that I use the wrong annotation for the index, but I cannot seem to find sample code or postings that illustrates how to do it, so this is my best guess. Is it the correct way to add an index?

NullPointerException thrown when an @Index annotation is used with a @ManyToMany:
Code:
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)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 11:08 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Can you post a JIRA issue with a reproducable testcase, the NPE is bad in all cases

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.