-->
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.  [ 7 posts ] 
Author Message
 Post subject: Native SQL Help...
PostPosted: Wed Jul 19, 2006 6:24 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
Hi.

If I have a table like TableA with ID, NAME, BINARY columns how can I retrive the TableA object without BINARY data ?

Is this query string appropriate:
select a.ID as {a.Id}, a.NAME as {a.Name} from TableA as a?

Tnx
markov


Top
 Profile  
 
 Post subject: ?
PostPosted: Thu Jul 20, 2006 10:41 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
can no one answer this question?

cause if i dont define binary field in my sql statement i get the exception from hibernate? is there any way to set no needed fields to null?

tnax
markov


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 20, 2006 1:45 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
The TableA object will return all the properties it has mapped to database columns. If you want to return only specific columns/properties, you have two choices.

Code:
select a.ID, a.NAME from TableA as a


or

Code:
select new MiniTableA( a.ID, a.NAME ) from TableA as a


This assumes that the MiniTableA object has the appropriate constructor signature, and has been included in the mappings.

http://www.hibernate.org/hib_docs/nhibernate/html/queryhql.html

This is a common question. I tried searching the forums to give you a link to previous questions, but oddly enough my searches returned no results.


Top
 Profile  
 
 Post subject: --
PostPosted: Fri Jul 21, 2006 2:06 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
hmmm, i never thought of defining a new mini object...i'll consider that. but i hoped it is posible to get the table object back but with only certain fields filled. like if you have a table with some fields containing binary data maybe you dont want allways to get that binary data but just some other fileds (to reduce the traffic and maybe improve the speed). doing this you still have your object but with the binary data set to null...

anyway it is good that i can still get my data in some other way so...choosing the right and easiest way to retrive table data in nhibernate drives me mad somethimes :)

tnx
markov


Top
 Profile  
 
 Post subject: Re: --
PostPosted: Fri Jul 21, 2006 10:29 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
markov wrote:
i hoped it is posible to get the table object back but with only certain fields filled.


You could mark that property as "lazy" and just not use it - it would not be filled until you access it.

markov wrote:
anyway it is good that i can still get my data in some other way so...choosing the right and easiest way to retrive table data in nhibernate drives me mad somethimes :)


I found that when I finally stopped thinking about tables and SQL and just thought in objects, using NH became infinitely easier. Your mileage may vary.


Top
 Profile  
 
 Post subject: --
PostPosted: Fri Jul 21, 2006 10:53 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
is that even possible in NHibernate?? I adapted the mapping xml:

<property column="content" type="Byte[]" name="Content" lazy="true" />

and have set the property to lazy but only got the following exception:

NHibernate.MappingException: Error reading resource: Application.Tables.
DocumentBinary.hbm.xml ---> NHibernate.MappingException: The 'lazy' attribute is not declared.

any idea?
tnx
markov


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 21, 2006 3:57 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
Sorry. I was still asleep when I wrote that.

I think the proper way is setting the class to be lazy but only make the properties you want to be lazy have the "virtual" modifier. So make only the byte[] property virtual. That's not a great solution, and I've never tried it myself, but it might work. :)


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