-->
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: one-to-many using same Class
PostPosted: Wed May 05, 2004 3:38 am 
Beginner
Beginner

Joined: Wed May 05, 2004 3:26 am
Posts: 25
Hibernate version 2.1.3
Mapping document

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="de.gloegl.road2hibernate">   

<class name="Port" table="fromto">
        <id name="id"  column="id"  type="java.lang.String"  unsaved-value="null"  length="32">
            <generator class="hilo"/>
        </id>

      <property name="abbreviation" column="originID" not-null="true"/>
        <property name="name" column="origin" not-null="true"/>

        <many-to-one name="origin"  class="Port"  column="destinationID"  cascade="none"  not-null="false"/>

        <set name="destinations"  table="fromto"  cascade="all"  inverse="true" lazy="false">
            <key column="originID"/>
            <one-to-many class="Port"/>
        </set>

    </class>
</hibernate-mapping>


Table structure [fromto]

Column_name
--------------
id
origin
originID
destination
destinationID


Requirement
To map every origin with a distinct origindID to all corresponding destinations

---------
I'm not sure whether the mapping is correct. When I try to execute the HQ "from Port" I get the following

Code:
WARN  - SQL Error: 102, SQLState: 42000
ERROR - Incorrect syntax near 'left'.

WARN  - SQL Error: 102, SQLState: 42000
ERROR - Incorrect syntax near 'left'.

ERROR - could not load: [de.gloegl.road2hibernate.Port#AXL]
com.sybase.jdbc2.jdbc.SybSQLException: Incorrect syntax near 'left'.


Thanks in advance :(

_________________
The Bits Control The Atoms


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 05, 2004 8:39 am 
Beginner
Beginner

Joined: Wed May 05, 2004 3:26 am
Posts: 25
Ok, I have changed the mapping to look like the following

Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN" "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping package="de.gloegl.road2hibernate">   

<class name="Port" table="fromto">
        <id name="id"  column="id"  type="java.lang.String"  unsaved-value="null"  length="32">
            <generator class="increment"/>
        </id>

      <property name="abbreviation" column="originID" not-null="true"/>
        <property name="name" column="origin" not-null="true"/>
       
        <many-to-one name="origin"  class="Port"  column="originID" insert="false" update="false" cascade="none"  not-null="false"/>

        <set name="destinations"  table="fromto"  cascade="all" inverse="true" lazy="false">
            <key column="destinationID"/>
            <one-to-many class="Port"/>
        </set>
</class>

</hibernate-mapping>


I can see the query from the log executing correctly
Code:
select port0_.id as id, port0_.originID as originID, port0_.origin as origin from fromto port0_ where (destinationID!='~~~' )


and calling size in the results List, comes up with the correct number, but when looking inside the results List, all elements are 'null' therefore getting a NPE.

Any help much appreciated...

_________________
The Bits Control The Atoms


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.