-->
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: Problem with order-by property
PostPosted: Fri Feb 27, 2009 8:27 pm 
Newbie

Joined: Fri Feb 27, 2009 7:57 pm
Posts: 1
Hibernate version :- hibernate-3.2.1.ga.

I am using a library example , the diagram is on this page at the top.
http://www.eclipse.org/modeling/emf/docs/1.x/tutorials/glibmod/glibmod_emf1.1.html#top

I have created the folowing already:
Library:My Library
Writer: JRR Tolkien
Book: The Hobbit

As a next step I am trying to add more books to an existing Writer.

I have a many-to-one relationship between book and writer
I have set cascade=persist, so that when i add a new book and save it, the existing writer gets persisted.

Code:
<many-to-one name="author" entity-name="Writer" lazy="false"
cascade="persist,save-update,lock" foreign-key="book_author" insert="true"
update="true" not-null="false">
   <column not-null="false" unique="false" name="`myauthor_id`"/>
</many-to-one>



There is a one-to-many relationship between writer and book. And the books are ordered by book_title.
Code:
<bag name="books" order-by="book_title" inverse="true" lazy="true"
cascade="merge,persist,save-update,lock">
   <key update="true">
    <column name="`myauthor_id`" not-null="false" unique="false"/>
   </key>
   <one-to-many entity-name="Book"/>
</bag>


Code to add more books
Code:
Query query = session.createQuery("FROM Library");
  List libraries = query.list();
  Library lib = (Library) libraries.get(0);

  System.out.println(lib.getName());
  // read a writer
  query = session.createQuery("FROM Writer where name='JRR Tolkien'");
  List<Writer> writers = query.list();
  Writer writer = writers.get(0);
  System.out.println(writer.getName());

// add  new books
  LibraryFactory libFactory = LibraryFactory.eINSTANCE;
  Book book1 = libFactory.createBook();
(119)  book1.setAuthor(writer);
  book1.setPages(306);
  book1.setTitle("HIJK");
  book1.setCategory(BookCategory.MYSTERY);
lib.getBooks().add(book1);



Hiberante mapping file:
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 auto-import="false">
   <class name="library.impl.BookImpl" entity-name="Book" abstract="false" lazy="false" table="`mybooktable`">
      <meta attribute="eclassName">Book</meta>
      <meta attribute="epackage">library.ecore</meta>
      <id name="id" type="java.lang.Integer">
         <column not-null="true" unique="false" name="`id`"/>
         <generator class="native"/>
      </id>
      <version name="version" type="int">
         <column not-null="false" unique="false" name="`writelock`"/>
      </version>
      <property name="title" lazy="false" insert="true" update="true" not-null="false" unique="false" type="java.lang.String">
         <column not-null="false" unique="false" name="`book_title`"/>
      </property>
      <property name="pages" lazy="false" insert="true" update="true" not-null="false" unique="false" type="int">
         <column not-null="false" unique="false" name="`page_count`"/>
      </property>
      <property name="category" lazy="false" not-null="true" insert="true" update="true" unique="false">
         <column not-null="true" unique="false" name="`category`"/>
         <type name="org.eclipse.emf.teneo.hibernate.mapping.ENumUserType">
            <param name="enumClass">library.BookCategory</param>
         </type>
      </property>
      <many-to-one name="author" entity-name="Writer" lazy="false" cascade="persist,save-update,lock" foreign-key="book_author" insert="true" update="true" not-null="false">
         <column not-null="false" unique="false" name="`myauthor_id`"/>
      </many-to-one>
   </class>
   <class name="library.impl.LibraryImpl" entity-name="Library" abstract="false" lazy="false" discriminator-value="Library" table="`library`">
      <meta attribute="eclassName">Library</meta>
      <meta attribute="epackage">library.ecore</meta>
      <id name="id" type="java.lang.Integer">
         <column not-null="true" unique="false" name="`id`"/>
         <generator class="native"/>
      </id>
      <discriminator column="`dtype`" type="string"/>
      <version name="version" type="int">
         <column not-null="true" unique="false" name="`version`"/>
      </version>
      <property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
         <column not-null="true" unique="false" name="`name`"/>
      </property>
      <list name="books" lazy="true" cascade="all,delete-orphan">
         <key update="true" foreign-key="library_books">
            <column name="`library_books_id`" not-null="false" unique="false"/>
         </key>
         <list-index column="`library_books_idx`"/>
         <one-to-many entity-name="Book"/>
      </list>
      <list name="writers" lazy="true" cascade="all,delete-orphan">
         <key update="true" foreign-key="library_writers">
            <column name="`library_writers_id`" not-null="false" unique="false"/>
         </key>
         <list-index column="`library_writers_idx`"/>
         <one-to-many entity-name="Writer"/>
      </list>
   </class>
   <class name="library.impl.WriterImpl" entity-name="Writer" abstract="false" lazy="false" discriminator-value="Writer" table="`writer`">
      <meta attribute="eclassName">Writer</meta>
      <meta attribute="epackage">library.ecore</meta>
      <id name="id" type="java.lang.Integer">
         <column not-null="true" unique="false" name="`id`"/>
         <generator class="native"/>
      </id>
      <discriminator column="`dtype`" type="string"/>
      <version name="version" type="int">
         <column not-null="true" unique="false" name="`version`"/>
      </version>
      <property name="name" lazy="false" insert="true" update="true" not-null="true" unique="false" type="java.lang.String">
         <column not-null="true" unique="false" name="`name`"/>
      </property>
      <bag name="books" order-by="book_title" inverse="true" lazy="true" cascade="merge,persist,save-update,lock">
         <key update="true">
            <column name="`myauthor_id`" not-null="false" unique="false"/>
         </key>
         <one-to-many entity-name="Book"/>
      </bag>
   </class>
</hibernate-mapping>



throws the following exception. How do I resolve this problem?

Code:
11:53:56,142 DEBUG JDBCExceptionReporter:108 - could not initialize a
collection: [Writer.books#5] [select books0_."myauthor_id" as myauthor6_1_,
books0_."id" as id1_1_, books0_."id" as id1_0_0_, books0_."writelock" as
writelock2_0_0_, books0_."book_title" as book3_0_0_, books0_."page_count" as
page4_0_0_, books0_."category" as category5_0_0_, books0_."myauthor_id" as
myauthor6_0_0_, books0_.econtainer_class as econtainer9_0_0_,
books0_.e_container as e10_0_0_, books0_.e_container_featureid as e11_0_0_,
books0_1_."level" as level2_3_0_, case when books0_1_."book_id" is not null
then 1 when books0_."id" is not null then 0 end as clazz_0_ from
"mybooktable" books0_ left outer join "schoolbook" books0_1_ on
books0_."id"=books0_1_."book_id" where books0_."myauthor_id"=? order by
books0_.book_title]
java.sql.SQLException: ORA-00904: "BOOKS0_"."BOOK_TITLE": invalid identifier

at
oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:111)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:330)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:287)
at oracle.jdbc.driver.T4C8Oall.receive(T4C8Oall.java:742)
at
oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:212)
at
oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:795)
at
oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1030)
at
oracle.jdbc.driver.T4CPreparedStatement.executeMaybeDescribe(T4CPreparedStatement.java:835)
at
oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1123)
at
oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3284)
at
oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3328)
at
org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1778)
at org.hibernate.loader.Loader.doQuery(Loader.java:662)
at
org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
at org.hibernate.loader.Loader.loadCollection(Loader.java:1985)
at
org.hibernate.loader.collection.CollectionLoader.initialize(CollectionLoader.java:36)

The fist line of the Exception has a query
When I execute it in Toad I get the following error
Code:
SELECT   books0_."myauthor_id" AS myauthor6_1_, books0_."id" AS id1_1_,
         books0_."id" AS id1_0_0_, books0_."writelock" AS writelock2_0_0_,
         books0_."book_title" AS book3_0_0_,
         books0_."page_count" AS page4_0_0_,
         books0_."category" AS category5_0_0_,
         books0_."myauthor_id" AS myauthor6_0_0_,
         books0_.econtainer_class AS econtainer9_0_0_,
         books0_.e_container AS e10_0_0_,
         books0_.e_container_featureid AS e11_0_0_
    FROM "mybooktable" books0_
   WHERE books0_."myauthor_id" = 5
ORDER BY books0_.book_title

"ORA-00904: "BOOKS0_"."BOOK_TITLE": invalid identifier"

But when i put quotes around book_title it works
Code:
SELECT   books0_."myauthor_id" AS myauthor6_1_, books0_."id" AS id1_1_,
         books0_."id" AS id1_0_0_, books0_."writelock" AS writelock2_0_0_,
         books0_."book_title" AS book3_0_0_,
         books0_."page_count" AS page4_0_0_,
         books0_."category" AS category5_0_0_,
         books0_."myauthor_id" AS myauthor6_0_0_,
         books0_.econtainer_class AS econtainer9_0_0_,
         books0_.e_container AS e10_0_0_,
         books0_.e_container_featureid AS e11_0_0_
    FROM "mybooktable" books0_
   WHERE books0_."myauthor_id" = 5
ORDER BY books0_."book_title"

why aren't there quotes in the orderby clause around book_title


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.