-->
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: Wrong SQL generated for formulas ?
PostPosted: Wed Sep 13, 2006 7:39 pm 
Newbie

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

I have exactly the scenario as described in Chapter "7.6. More complex association mappings"
I have a historized table "leaf" which includes 4 columns "lid", "start", "end" and "parentid" where parentid points to another lid.
So the content could be something like this:

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

First I thought the problem described below is, that the same table/class is referenced inside the properties-node but even with duplicated tables/classes with different names, i get the problem that the generated SQL is not correct.

Does anybody have an idea, what I'm doing wrong ?

Thanks in advance,
Dirk

And here the code and error details:


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.