-->
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: Named SQL Query in Mapping - beginner question
PostPosted: Mon Sep 01, 2008 1:56 pm 
Newbie

Joined: Mon Sep 01, 2008 12:20 pm
Posts: 3
I read through the Introduction chapter today (ok - I skimmed throught it) but couldnt find any answers to my questions there, nor in the FAQ.

Im a newcomer to Hibernate and trying to finish off what someone started :(

I have a mapping file as below for a User (a bit stripped down for clarity).




User.hbm.xml
----------------

<hibernate-mapping>

<class name="com.myApp.user.User" table="USER">

<id name="id" type="java.lang.Long">
<column name="ID" />
<generator class="native" />
</id>

<many-to-one name="domain" class="com.myApp.person.Domain" fetch="join">
<column name="DOMAIN_ID" not-null="true" />
</many-to-one>

<property name="emailAddress" type="java.lang.String">
<column name="EMAIL_ADDRESS" length="80" not-null="true" />
</property>

<property name="password" type="java.lang.String">
<column name="PASSWORD" length="25" not-null="true" />
</property>

<set name="userAddresses" inverse="true" cascade="all">
<key>
<column name="USER_ID" not-null="true" />
</key>
<one-to-many class="com.myApp.user.UserAddress" />
</set>

</class>
</hibernate-mapping>



My problem lies with the password field. I have an existing database of users who had their passwords encrypted using the mySql encode() function. So basically I wish to write a bit of SQL to run this native function for the password fetching.

My problem is that I dont understand Hibernate enough yet to figure out whether I can implement some SQL just for 1 field rathe than having to write the whole SELECT statement for getting the user/s.

I did look through chapter 16 of the documentation on Native SQL but couldnt find examples in there to help me out.
http://www.hibernate.org/hib_docs/v3/re ... rysql-load


The DAO is making use of a Criteria implementation:

get() method
---------------

Criteria criteria = getSession().createCriteria(type);
criteria.add(Restrictions.eq(MappingConstants.EMAIL_ADDRESS, emailAddress));
createCriteria(criteria, MappingConstants.DOMAIN, MappingConstants.CODE, domainCode);
List<T> dataObjList = criteria.list();



Any suggestions as to where to find the information I need is greatly appreciated from this newcomer.


Jon


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.