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 

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
<?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 -->
  <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"/>
    <property name="lastName" type="string">
      <column name="`Last Name`" not-null="true"/>
    <property name="firstName" type="string">
      <column name="`First Name`" not-null="true"/>
    <property name="ini" type="string">
      <column name="Ini"/>
    <property name="nickname" type="string">
      <column name="Nickname" not-null="true"/>
    <property name="ssn" type="string">
      <column name="SSN"/>
    <property name="Emp_num" type="java.lang.Integer">
      <column name="`Emp#`"/>
    <property name="probation" type="boolean">
      <column name="Probation" not-null="true"/>
    <property name="hireDate" type="timestamp">
      <column length="23" name="`Hire Date`"/>
    <property name="termDate" type="timestamp">
      <column length="23" name="`Term Date`"/>
    <property name="meritAnniversary" type="timestamp">
      <column length="23" name="`Merit Anniversary`"/>
    <property name="payStep" type="string">
      <column name="`Pay Step`"/>
    <property name="nextEval" type="timestamp">
      <column length="23" name="`Next Eval`"/>
    <property name="arriveWork" type="timestamp">
      <column length="23" name="`Arrive Work`"/>
    <property name="departWork" type="timestamp">
      <column length="23" name="`Depart Work`"/>
    <property name="lunchStart" type="timestamp">
      <column length="23" name="`Lunch Start`"/>
    <property name="lunchEnd" type="timestamp">
      <column length="23" name="`Lunch End`"/>
    <property name="notaryExpiration" type="timestamp">
      <column length="23" name="`Notary Expiration`"/>
    <property name="ParkingTag_num" type="string">
      <column name="`Parking Tag #`"/>
    <property name="actingPcn" type="string">
      <column name="`Acting PCN`"/>
    <property name="CardGroup_num" type="java.lang.Integer">
      <column name="`CardGroup#`"/>
    <property name="processSrvLic" type="boolean">
      <column name="ProcessSrvLic" not-null="true"/>
    <set fetch="select" inverse="true" name="systemTables" table="SystemTable" lazy="true">
        <column name="`Name IRC`" not-null="true"/>
      <one-to-many class="us.ak.state.revenue.cssd.Personnel.dao.SystemTable" />
    <!-- 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"/>
      <id name="pcn" type="string">
        <column name="PCN"/>
        <generator class="assigned"/>
      <property name="typeOfPcn" type="string">
        <column name="`Type of PCN`"/>
      <property name="systPcn" type="string">
        <column name="`SYST PCN`"/>
      <property name="mailstop" type="string">
        <column name="Mailstop"/>
      <property name="subTeam" type="string">
        <column name="SubTeam"/>
      <property name="phonePrefix" type="string">
        <column name="`Phone Prefix`"/>
      <property name="phoneExt" type="string">
        <column name="`Phone Ext`"/>
      <property name="faxPrefix" type="string">
        <column name="`Fax Prefix`"/>
      <property name="faxExt" type="string">
        <column name="`Fax Ext`"/>
      <property name="pager" type="string">
        <column name="Pager"/>
      <property name="positionTitle" type="string">
        <column name="`Position Title`"/>
      <property name="supervisorPcn" type="string">
        <column name="`Supervisor PCN`"/>
      <property name="phoneList" type="boolean">
        <column name="`Phone List?`" not-null="true"/>
      <property name="phoneListDescription" type="string">
        <column name="`Phone List Description`"/>
      <property name="supervisory" type="string">
        <column name="`Supervisory?`" not-null="true"/>
      <property name="PCNList" type="boolean">
        <column name="`PCN List?`" not-null="true"/>
      <property name="payRange" type="string">
        <column name="`Pay Range`"/>
      <property name="actingIrc" type="java.lang.Integer">
        <column name="`Acting IRC`"/>
      <property name="actingEndDate" type="timestamp">
        <column length="23" name="`Acting End Date`"/>
      <property name="comments" type="string">
        <column name="Comments"/>
      <!-- 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" />
    <filter name="hack_filter" condition="1=1"></filter>
  <filter-def name="hack_filter">   

Thanks in advance for any help,

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.