-->
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: Default schema is not added to native SQL
PostPosted: Tue Jul 29, 2008 10:41 am 
Newbie

Joined: Tue Jul 29, 2008 10:09 am
Posts: 3
Hi,

When I do a native SQL query I have to add the schema name, so I have to do:
sess.createSQLQuery("SELECT * FROM [schema name].[table name]")

I have set a default_schema in my properties file. Is there a way that this default schema name is added?

Thanks, Michiel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 7:54 am 
Expert
Expert

Joined: Tue May 13, 2008 3:42 pm
Posts: 919
Location: Toronto & Ajax Ontario www.hibernatemadeeasy.com
Well, you really probably want to do an HQL query, don't you?

If you're going to the trouble of setting up Hibernate, doing an SQL query is a bit of a step backwards.

Look at this tutorial on mastering HQL and Hibernate Queries:

http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries

If you had a Java class POJO named User, you might do an HQL query like this:

Code:
Session session = HibernateUtil.beginTransaction();
String loginName = "mj";
String hql="from User where loginName = :name";
Query query = session.createQuery(hql);
query.setString("name", loginName);
Object o = query.uniqueResult();
User user = (User)o;
System.out.println(user.getLoginName());
HibernateUtil.commitTransaction();


http://jpa.ezhibernate.com/Javacode/learn.jsp?tutorial=08masteringhqlandnamedqueries

_________________
Cameron McKenzie - Author of "Hibernate Made Easy" and "What is WebSphere?"
http://www.TheBookOnHibernate.com Check out my 'easy to follow' Hibernate & JPA Tutorials


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 30, 2008 11:42 am 
Newbie

Joined: Tue Jul 29, 2008 10:09 am
Posts: 3
If I would build a new application I would of course use HQL or criterias. However I am migrating an EJB entity/session bean application to Hibernate and Spring and we have a lot of SQL queries which we do not want to migrate. Therefore I want to execute the SQL, which is working fine except for the schema name that must be added in the sql. A sollution for this problem would be very nice.


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.