-->
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.  [ 2 posts ] 
Author Message
 Post subject: Naming tables in dao
PostPosted: Sun Oct 19, 2008 5:47 pm 
Beginner
Beginner

Joined: Sat Dec 01, 2007 4:34 pm
Posts: 20
In my project I got a table where I register when a user logs on.

When I changed the name of the log table, I had to change the name in all the sql statements.

Is there a better way to do this? I thought about using a constant. Is that a good solution?

Code:
public class UserLogDaoImpl implements UserLogDao {

  private static final String TABLE_NAME = "UserLog";
   
  public List getLogsByUsername(String username, int i){
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    List logs = session.createQuery("select l from TABLE_NAME as l where l.username=:u").setMaxResults(i).setString("u", username).list();
    session.getTransaction().commit();

    return logs;
  }




Top
 Profile  
 
 Post subject: Re: Naming tables in dao
PostPosted: Sun Oct 19, 2008 9:30 pm 
Newbie

Joined: Wed Oct 15, 2008 6:50 am
Posts: 4
vator wrote:
In my project I got a table where I register when a user logs on.

When I changed the name of the log table, I had to change the name in all the sql statements.

Is there a better way to do this? I thought about using a constant. Is that a good solution?

Code:
public class UserLogDaoImpl implements UserLogDao {

  private static final String TABLE_NAME = "UserLog";
   
  public List getLogsByUsername(String username, int i){
    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();

    List logs = session.createQuery("select l from TABLE_NAME as l where l.username=:u").setMaxResults(i).setString("u", username).list();
    session.getTransaction().commit();

    return logs;
  }




why not use hql ?Such as "from Pojo where username=x".Then change your hbm.xml will change everything.
or, use dynamicMode.
...etc .
Is that what u want?


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