-->
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.  [ 4 posts ] 
Author Message
 Post subject: Criteria problem
PostPosted: Thu Feb 22, 2007 6:36 am 
Newbie

Joined: Thu Feb 22, 2007 6:15 am
Posts: 7
Hello,

I starting to manipulate Hibernate with a simple database, and in particular I'm working with criteria API on Eclipse.
My database is only composed of 3 tables:
Code:
Author
  number
  name

Book
  number
  title
  year

WrittenBy
   author_num
   book_num


I created config file, generated the HBM files and java code.

Code:
public class Author implements java.io.Serializable
{
   private int number;
   private String name;
   private Set books = new HashSet(0);
        ...
}

public class Book implements java.io.Serializable
{
   private int number;
   private String title;
   private Short year;
   private Set authors = new HashSet(0);
        ...
}


I started working with criteria with easy requests on 1 table: working with restriction, projection, order...
Everything's fine.
But now, I'm interrogating 2 tables and it doesn't work.
This is for instance what I tested
Code:
Criteria c1=session.createCriteria(Book.class);
Criteria c2=c1.createCriteria("authors");
c2.add(Restrictions.ilike("name", "%erg%"));
list=c1.list();

and this what I received
Quote:
Caused by: org.postgresql.util.PSQLException: ERROR: relation "authors" does not exist

Any idea ? because everything seems to be declared normally ![/code]


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 7:10 am 
Expert
Expert

Joined: Tue Jan 30, 2007 12:45 am
Posts: 283
Location: India
Hi funkadeclic,
for this
Criteria c1=session.createCriteria(Book.class);
Criteria c2=c1.createCriteria("authors");
c2.add(Restrictions.ilike("name", "%erg%"));
list=c1.list();

author should be associated in HBM wih book.Either bag,set etc.

_________________
Dharmendra Pandey


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 7:19 am 
Newbie

Joined: Thu Feb 22, 2007 6:15 am
Posts: 7
Thank you for your answer.
But author is already associated in Book HBM file:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="Book" table="book" schema="public">
        <id name="number" type="int">
            <column name="number" />
            <generator class="assigned" />
        </id>
        <property name="title" type="string">
            <column name="title" not-null="true" />
        </property>
        <property name="year" type="java.lang.Short">
            <column name="year" />
        </property>
        <set name="authors" inverse="true">
            <key>
                <column name="book_num" not-null="true" />
            </key>
            <many-to-many entity-name="Author">
                <column name="author_num" not-null="true" />
            </many-to-many>
        </set>
    </class>
</hibernate-mapping>


Maybe there are some attributes I have to add in tags ?
I really don't know.
Any idea ?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 22, 2007 9:10 am 
Newbie

Joined: Thu Feb 22, 2007 6:15 am
Posts: 7
I finally solved my problem.
For those who are interested, in the HBM files, I had to add the join table name :
<set name="authors" inverse="true" table="writtenby">
And this was not done by the automatic code generation.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.