-->
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.  [ 3 posts ] 
Author Message
 Post subject: Native SQL queries
PostPosted: Mon Jun 27, 2005 2:32 pm 
Newbie

Joined: Mon Jun 27, 2005 2:13 pm
Posts: 5
Hi,
I am new to hibernate and have a question . I have a table which is created in mysql called RULES
and has the following colums

int id,
field varchar(20),
operator varchar(10),
value varchar(20)

This was an existing table and I have to use it as read only.

Now I want to use hibernate to retrieve results from this table.

since there was not any object model when this table was created, I have created a class called Rule with member names corresponding column names and mapped it to table RULES as shown below

<hibernate-mapping>
<class name="package.Rule" table="RULES">
</class>

</hibernate-mapping>

In my hibernate.cfg.xml, I am referring to the above mapping file in <mapping resource="package.filename" />

In my code I tried to creates SQL query as shown below

Query q = session.createSQLQuery("select {r.*} from RULES r where id := id").addEntity("r",Rule.class);

I get the error Rule.class not found.

can some one tell what is the right way of querying and existing table using SQL queries and also how to do it through named SQL queries.

thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 8:36 am 
Regular
Regular

Joined: Thu Apr 29, 2004 5:08 pm
Posts: 56
Location: Montreal, Quebec, Canada
An entity is an object, not a class.

You are doing

Code:
.addEntity("r",Rule.class);


This is nonsense.

But anyway, what you really want to do is to get all Rules out of the db. You can do that with a simple HQL query (why are you using a SQLQuery?) by doing "from Rule" which would return a list of all rule entities in the db.

_________________
- Frank


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 28, 2005 9:03 am 
Newbie

Joined: Mon Jun 27, 2005 2:13 pm
Posts: 5
thank you


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