-->
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: Ungültiges SQL bei Formulas in many-to-one
PostPosted: Thu Sep 14, 2006 6:35 am 
Newbie

Joined: Tue Dec 14, 2004 8:30 am
Posts: 9
Hallo,

ich habe genau das Szenario, wie es in
Chapter "7.6. More complex association mappings"
der Doku beschrieben ist, naemlich eine historisierte Tabelle.

Die Tabelle beinhaltet u.a. die folgenden Spalten:
"lid", "start", "end" und "parentid"
Parent-ID ist nun wiederum eine Referenz auf die lid einer anderen Zeile.

Beispiel:
lid, start, end, parentid
1, 2006-09-01, 2006-09-02, NULL
1, 2006-09-02, NULL, NULL
2, 2006-09-02, NULL, 1

Es gibt also 2 Versionen mit einer lid=1 von der eine noch gültig ist, da das Ende-Datum leer ist. Ich möchte nun für den Datensatz mit der lid=2 und der parentid=1 eine Bindung herstellen. Aber nur genau zu dem Satz ohne end-Datum (also "where end is null")

Dieses Szenario wollte ich nun wie in der Doku beschrieben über Properties und ein many-to-one abbilden. Leider ist das SQL was dabei entsteht aber nicht korrekt. Die genaue Fehlerbeschreibung folgt unten.

Mache ich etwas falsch und wenn ja, was ?

Vielen Dank im voraus,
Dirk

Mapping documents:
Code:
<class name="sandbox.model.Leaf" table="leaf" entity-name="Leaf">
    <id name="id"  type="short" column="id" >
        <generator class="native">
        </generator>
    </id>
    <property name="start" column="start" type="timestamp" length="19" not-null="true" />
    <property name="end" column="end" type="timestamp" length="19" not-null="false"/>

    <many-to-one name="parent"
        property-ref="customKey"
        class="Leaf">
        <column name="parentid"/>
        <formula>'1'</formula>
    </many-to-one>
   
    <properties name="customKey">
        <property name="lid" type="short" not-null="false" insert="false" update="false"/>
        <property name="isCurrent" type="boolean">
            <formula>case when end is null then 1 else 0 end</formula>
        </property>
    </properties>
</class>


Full stack trace of any exception that occurs:

org.springframework.jdbc.BadSqlGrammarException: Hibernate operation: could not load an entity: [Leaf#component[lid,isCurrent]{lid=null, isCurrent=true}]; bad SQL grammar [select leaf0_.id as id0_0_, leaf0_.start as start0_0_, leaf0_.end as end0_0_, leaf0_.parentid as parentid0_0_, leaf0_.lid as lid0_0_, '1' as formula0_0_, case when end is null then 1 else 0 end as formula1_0_ from leaf leaf0_ where leaf0_.lid=? and leaf0_.null=?]; nested exception is java.sql.SQLException: Unknown column 'leaf0_.null' in 'where clause'
java.sql.SQLException: Unknown column 'leaf0_.null' in 'where clause'
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2851)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1534)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1625)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2297)
at com.mysql.jdbc.Connection.execSQL(Connection.java:2226)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1812)
at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1657)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1669)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)

Name and version of the database you are using:
MySQL + Oracle (both with the same problem)

The generated SQL (show_sql=true):
select currentlea0_.id as id1_0_, currentlea0_.start as start1_0_, currentlea0_.lid as lid1_0_, currentlea0_.end as end1_0_, case when end is null then 1 else 0 end as formula1_0_ from currentleaf currentlea0_ where currentlea0_.lid=? and currentlea0_.null=?

The database creation script:
CREATE TABLE `leaf` (
`id` smallint(6) NOT NULL auto_increment,
`lid` smallint(6) NOT NULL,
`start` datetime NOT NULL,
`end` datetime default NULL,
`parentid` smallint(6) default NULL,
KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;


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.