-->
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: Native SQL -- Does addJoin() work?
PostPosted: Tue Aug 30, 2011 6:32 pm 
Newbie

Joined: Wed Dec 29, 2010 6:36 pm
Posts: 5
There are many similarly titled posts on here where the author is talked away from using native sql. In my case, I require a union, which, correct me if I'm wrong, isn't supported in hql or criteria, so I must go native. Now that I've done so, I need to work optimistic fetching back into my implementation and it seems like addJoin() doesn't do anything. I get no stack-traces and the result returns accurately but with lazy fetches.

Tables:
user = {user_id, user_profile_id}
user_profile = {user_profile_id, fname, lname}

Entities:
User = {userProfile}
UserProfile = {fname, lname}

Code w/ Native SQL (super-simplified):
Code:
                SQLQuery query = session.createSQLQuery("" +
                        "select " +
                        "  {user.*}, " +
                        "  {userProfile.*} " +
                        "from " +
                        "  user user, "+   //<-- in my actual code, "user" serves as an alias for the results of my union subsql
                        "  user_profile userProfile "+
                        "where " +
                        "  user.user_id = userProfile.user_id " +
                        "order by " +
                        "  userProfile.fname, " +
                        "  userProfile.lname " +
                        ""
                );
                query.addEntity("user", User.class);
                query.addJoin("userProfile", "user.userProfile");
                return query.list();



Seems pretty straight-forward and this should optimistically join userProfile data to the user.userProfile attribute in the ORM, but it doesn't.

Does native sql addJoin() work?


Thanks.


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.