-->
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: Child-parent association
PostPosted: Wed Jul 07, 2010 1:44 am 
Newbie

Joined: Mon Nov 23, 2009 2:33 am
Posts: 5
Good day! I have quite primitive problem. There are two tables:

Code:
CREATE TABLE VSTATUSDATE (
    ID        BIGINT NOT NULL,
    TKP       BIGINT NOT NULL,
    ...
);

and

CREATE TABLE VTKP (
    ID          BIGINT NOT NULL,
    ...
);

Foreign key: ALTER TABLE VSTATUSDATE ADD CONSTRAINT FK_VTKPSTATUSDATE_TKP FOREIGN KEY (TKP) REFERENCES VTKP (ID);

And mappings:

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">
<hibernate-mapping>
  <class name="brescore.VStatusDate" table="VSTATUSDATE">
    <id name="id" type="long">
      <column name="ID"/>
      <generator class="native"/>
    </id>
    <property name="date" type="timestamp">
      <column name="DT" not-null="true"/>
    </property>
    <many-to-one class="brescore.VTKP" column="TKP" name="tkp" not-null="true"/>
    <many-to-one class="brescore.auxi.VStatus" column="STATUS" fetch="select" name="status" not-null="true"/>
    <many-to-one class="brescore.VEmployee" column="EMPLOYEE" fetch="select" name="employee" not-null="true"/>
</class>
</hibernate-mapping>

<?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">
<hibernate-mapping>
  <class name="brescore.VTKP" table="VTKP">
    <id name="id" type="long">
      <column name="ID"/>
      <generator class="native"/>
    </id>
    <property name="num" type="string">
      <column length="10" name="NUM" not-null="true"/>
    </property>
    <property name="outNum" type="string">
      <column length="10" name="OUTNUM" not-null="false"/>
    </property>
    <property lazy="true" name="doc" type="binary">
      <column name="DOC" not-null="false"/>
    </property>
    <property lazy="true" name="docName" type="string">
      <column name="DOCNAME" not-null="false"/>
    </property>
    <property name="summa" formula="(select sum(t.q*t.price) from vtkpposition t where t.tkp=id)" type="double"/>
    <property name="sendDt" formula="(select max(t.dt) from vstatusdate t where t.tkp=id and t.status=-50)" type="timestamp"/>
    <many-to-one class="brescore.VOrg" column="CLIENT" name="client"/>
    <many-to-one class="brescore.VEmployee" column="SPECIALIST" name="specialist" not-null="true"/>
    <many-to-one class="brescore.VEmployee" column="AGENT" name="agent" not-null="false"/>
    <many-to-one class="brescore.VEnergoObject" column="ENOBJ" name="energoobject"/>
    <bag name="statuses" cascade="all-delete-orphan" lazy="false" fetch="select">
        <key column="ID" />
        <one-to-many class="brescore.VStatusDate" not-found="exception"/>
    </bag>
  </class>
</hibernate-mapping>


When I write new statuses it works fine, but select is wrong:
Code:

Hibernate: /* load one-to-many brescore.VTKP.statuses */ select statuses0_.ID as ID1_, statuses0_.ID as ID18_0_, statuses0_.DT as DT18_0_, statuses0_.TKP as TKP18_0_, statuses0_.STATUS as STATUS18_0_, statuses0_.EMPLOYEE as EMPLOYEE18_0_ from VSTATUSDATE statuses0_ where statuses0_.ID=?

Must be
Code:
Hibernate: /* load one-to-many brescore.VTKP.statuses */ select statuses0_.ID as ID1_, statuses0_.ID as ID18_0_, statuses0_.DT as DT18_0_, statuses0_.TKP as TKP18_0_, statuses0_.STATUS as STATUS18_0_, statuses0_.EMPLOYEE as EMPLOYEE18_0_ from VSTATUSDATE statuses0_ where statuses0_.TKP=?


What is wrong in my mappings?


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.