-->
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.  [ 1 post ] 
Author Message
 Post subject: Self Referencing Foreign Key problem
PostPosted: Mon Jun 07, 2010 4:43 pm 
Newbie

Joined: Wed May 12, 2010 8:29 pm
Posts: 4
I have an Entity Employee, that maps to 2 database tables using a join.
Employee has a property supervisorPcn that maps to pcn. Both of these properties
map to the joined table for my employee entity. I'm trying to get my employee entity
to lazy load this property.

I keep getting "SQLServerException: Invalid column name." when I try to instantiate an instance of the entity. Looking at the generated SQL it looks like Hibernate is trying to access PCN (the referenced Foreign Key) as if it where part of the table that the second table is joined to.
Example SQL: Select * FROM [Name Table],[PCN-Table] where [Name Table].PCN='1234';
Should be: Select * FROM [Name Table],[PCN-Table] where [PCN-Table].PCN='1234';

I'm using Hibernate 3.3.2GA

Here is my mapping file
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
          "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!-- Generated Mar 9, 2010 11:59:10 AM by Hibernate Tools 3.2.4.GA -->
<!-- TODO: fix this file to properly map NameTable/PcnTAble for employee -->
<hibernate-mapping>
  <class catalog="Personnel" schema="dbo" table="`Name Table`"
         name="us.ak.state.revenue.cssd.Personnel.Employee.Employee" >
    <id name="nameIrc" type="int">
      <column name="`Name IRC`"/>
      <generator class="identity"/>
    </id>
    <property name="lastName" type="string">
      <column name="`Last Name`" not-null="true"/>
    </property>
    <property name="firstName" type="string">
      <column name="`First Name`" not-null="true"/>
    </property>
    <property name="ini" type="string">
      <column name="Ini"/>
    </property>
    <property name="nickname" type="string">
      <column name="Nickname" not-null="true"/>
    </property>
    <property name="ssn" type="string">
      <column name="SSN"/>
    </property>
    <property name="Emp_num" type="java.lang.Integer">
      <column name="`Emp#`"/>
    </property>
    <property name="probation" type="boolean">
      <column name="Probation" not-null="true"/>
    </property>
    <property name="hireDate" type="timestamp">
      <column length="23" name="`Hire Date`"/>
    </property>
    <property name="termDate" type="timestamp">
      <column length="23" name="`Term Date`"/>
    </property>
    <property name="meritAnniversary" type="timestamp">
      <column length="23" name="`Merit Anniversary`"/>
    </property>
    <property name="payStep" type="string">
      <column name="`Pay Step`"/>
    </property>
    <property name="nextEval" type="timestamp">
      <column length="23" name="`Next Eval`"/>
    </property>
    <property name="arriveWork" type="timestamp">
      <column length="23" name="`Arrive Work`"/>
    </property>
    <property name="departWork" type="timestamp">
      <column length="23" name="`Depart Work`"/>
    </property>
    <property name="lunchStart" type="timestamp">
      <column length="23" name="`Lunch Start`"/>
    </property>
    <property name="lunchEnd" type="timestamp">
      <column length="23" name="`Lunch End`"/>
    </property>
    <property name="notaryExpiration" type="timestamp">
      <column length="23" name="`Notary Expiration`"/>
    </property>
    <property name="ParkingTag_num" type="string">
      <column name="`Parking Tag #`"/>
    </property>
    <property name="actingPcn" type="string">
      <column name="`Acting PCN`"/>
    </property>
    <property name="CardGroup_num" type="java.lang.Integer">
      <column name="`CardGroup#`"/>
    </property>
    <property name="processSrvLic" type="boolean">
      <column name="ProcessSrvLic" not-null="true"/>
    </property>
    <set fetch="select" inverse="true" name="systemTables" table="SystemTable" lazy="true">
      <key>
        <column name="`Name IRC`" not-null="true"/>
      </key>
      <one-to-many class="us.ak.state.revenue.cssd.Personnel.dao.SystemTable" />
    </set>
    <!-- I think the join element goes here -->
    <join catalog="Personnel" schema="dbo" table="`PCN-Table`">
      <!--<key column="PCN"  on-delete="noaction" unique="true" /> -->
      <key column="`Name IRC`" on-delete="noaction" property-ref="nameIrc"/>
      <property name="pcn" not-null="true" type="string">
        <column name="PCN"/>
      </property>
      <!--
      <id name="pcn" type="string">
        <column name="PCN"/>
        <generator class="assigned"/>
      </id>
      <property name="typeOfPcn" type="string">
        <column name="`Type of PCN`"/>
      </property>
      -->     
      <property name="systPcn" type="string">
        <column name="`SYST PCN`"/>
      </property>
      <!--
      <property name="mailstop" type="string">
        <column name="Mailstop"/>
      </property>
      -->
      <property name="subTeam" type="string">
        <column name="SubTeam"/>
      </property>
      <property name="phonePrefix" type="string">
        <column name="`Phone Prefix`"/>
      </property>
      <property name="phoneExt" type="string">
        <column name="`Phone Ext`"/>
      </property>
      <property name="faxPrefix" type="string">
        <column name="`Fax Prefix`"/>
      </property>
      <property name="faxExt" type="string">
        <column name="`Fax Ext`"/>
      </property>
      <property name="pager" type="string">
        <column name="Pager"/>
      </property>
      <property name="positionTitle" type="string">
        <column name="`Position Title`"/>
      </property>
      <!--
      <property name="supervisorPcn" type="string">
        <column name="`Supervisor PCN`"/>
      </property>
      -->
      <property name="phoneList" type="boolean">
        <column name="`Phone List?`" not-null="true"/>
      </property>
      <property name="phoneListDescription" type="string">
        <column name="`Phone List Description`"/>
      </property>
      <!--
      <property name="supervisory" type="string">
        <column name="`Supervisory?`" not-null="true"/>
      </property>
      -->
      <property name="PCNList" type="boolean">
        <column name="`PCN List?`" not-null="true"/>
      </property>
      <property name="payRange" type="string">
        <column name="`Pay Range`"/>
      </property>
      <property name="actingIrc" type="java.lang.Integer">
        <column name="`Acting IRC`"/>
      </property>
      <property name="actingEndDate" type="timestamp">
        <column length="23" name="`Acting End Date`"/>
      </property>
      <property name="comments" type="string">
        <column name="Comments"/>
      </property>
      <!-- TODO: set these up to lazy load -->
      <many-to-one name="typeOfPcn" column="`Type of PCN`" fetch="join" />
      <many-to-one name="mailstop" column="Mailstop"
                   property-ref="mailStop" fetch="join" not-null="true" lazy="proxy"
                   class="us.ak.state.revenue.cssd.Personnel.dao.TeamDescription" />
      <many-to-one name="supervisory" column="`Supervisory?`" not-null="true"
                   property-ref="supervisory" fetch="join" lazy="proxy"
                   class="us.ak.state.revenue.cssd.Personnel.dao.SupervisoryDescription" />

      <!-- TODO: lazy load this so I'm not recursively loading a gigantic stack for one emp. -->
      <many-to-one name="supervisorPcn" column="`Supervisor PCN`"
                   property-ref="pcn" lazy="proxy" fetch="select"
                   class="us.ak.state.revenue.cssd.Personnel.Employee.Employee" />
   
    </join>
    <filter name="hack_filter" condition="1=1"></filter>
  </class>
  <filter-def name="hack_filter">   
  </filter-def>
</hibernate-mapping>


Thanks in advance for any help,
Raystorm


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

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.