-->
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.  [ 7 posts ] 
Author Message
 Post subject: orm.xml and many-to-many/join-table potential problem
PostPosted: Fri Dec 21, 2007 5:03 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
I'm attempting to implement a solution using only XML instead of annotations for JPA persistence.

Hibernate Entity Manager 3.3.1.ga

However, I've run into a snag where for an XML segment like this:

<many-to-many name="teachers" mapped-by="students" target-entity="Teachers" >
<join-table name="MYTEACHER_MYSTUDENT" >
<join-column name="TEACHER_ID"/>
<inverse-join-column name="STUDENT_ID"/>
</join-table>
</many-to-many>


The join table does not seem to be recognize - it throws something like this:

Code:
Dec 21, 2007 3:45:33 PM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: Invalid object name 'TEACHERS_STUDENTS'.


TEACHERS and STUDENTS are the respective table names of the entities, but defining my own join-table name 'MYTEACHER_MYSTUDENT' it ignores this. Creating a table to match what it wants partially corrects the problem, but I would like someone else with more experience to verify if this is a real problem or just my ignorance.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Dec 21, 2007 5:06 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
And the followup is that the join-columns also seem to have problems (wanting something like teacher_id_TEACHERS and student_id_STUDENTS for column names instead of what was defined).


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 22, 2007 5:31 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
it might be a small bug in the orm.xml parsing. Please open a JIRA issue with a minimal runnable test case.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 10:07 am 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
JIRA: http://opensource.atlassian.com/project ... se/ANN-687


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 11:36 am 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Is this handled in the Annotations jar -> o.h.cfg.annotations.reflections.EJB3OverriddenAnnotation.class?

I need this to work correctly to use the spec, so if you can help point me in the right direction I'll work on an internal patch so I can keep moving forward and publish any findings/corrections.

Code:
   private Columns buildColumns(Element element) {
      List<Element> subelements = element.elements( "column" );
      List<Column> columns = new ArrayList<Column>( subelements.size() );
      for (Element subelement : subelements) {
         columns.add( getColumn( subelement, false, element ) );
      }
      if ( columns.size() > 0 ) {
         AnnotationDescriptor columnsDescr = new AnnotationDescriptor( Columns.class );
         columnsDescr.setValue( "columns", columns.toArray( new Column[columns.size()] ) );
         return AnnotationFactory.create( columnsDescr );
      }
      else {
         return null;
      }
   }




Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 04, 2008 12:59 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
partial success with the column names not being respected.

If you use the attribute override tag to 'rename' the column, this tag is respected.

note that the column name I am 'overriding' is the same one that is expected by the relation mapping lookup. More testing to do from that other side if the attribute-override will work there or not.

Code:
        <id-class class="UserLocationsId"/>
        <!-- regular column names do not work,
        so attribute-override (but before attributes elements) -->
        <attribute-override name="locationId">
            <column name="locations_LOCATION_ID"/>
        </attribute-override>   
        <attribute-override name="userId">
            <column name="useraccounts_USER_ID"/>
        </attribute-override>   
       
        <attributes>
            <id name="locationId">
                <column name="locations_LOCATION_ID"/>
            </id>
            <id name="userId">
                <column name="useraccounts_USER_ID"/>
            </id>
        </attributes>


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 05, 2008 6:44 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Quote:
Is this handled in the Annotations jar -> o.h.cfg.annotations.reflections.EJB3OverriddenAnnotation.class?


Yes all the overriding strategy is there.

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.