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: Creating Reusable/Extendable Models and DAOs
PostPosted: Fri Jan 20, 2006 1:25 pm 
Beginner
Beginner

Joined: Thu Nov 20, 2003 1:30 pm
Posts: 27
With the latest version of Hibernate...

Basically what I am trying to achieve is to create a generic model and DAOs to be extended/used by other projects.

For instance every project I work on requires a Member class, Email class and EmailLog class.

So rather than me copy/recreate a member's system, e-mail sending/logging system for every project it would be nice if I can reuse one generic version and extend it. So the generic Member would have fields id and emailAddress, then for a specific project I can extend Member and add fields specific for that project. AND I can use the generic DAOs too. So it would be cool if I could do something like genericMemberDAO.isEmailSent(extendedMember, genericEmail).

So, you can see the problem I have is that of relationships between the genericModel and the extended model. If I pass an extended model to a generic DAO it will say it doesn't know anything about it.

Is the only way to achieve what I am looking for by components?

The only reason I don't really want to use component is it wouldn't seamlessly be OO based, meaning I would have to be creating and setting the generic components on the 'extended' model, an extra step. If possible

If anyone has any suggestions it would be helpful, like I said, I resuse a lot of the same model/DAO for different project, it would be nice to have a library of this.

Another option I thought of would be to just have the generic model have its own set of tables and the extended have its own. generic_member extended_member, etc, this would work, but I would rather not have the performance impact of joining/updating 2 tables when I could really be 1.

Thanks in advance - Joe


Top
 Profile  
 
 Post subject: Generic user/email class?
PostPosted: Fri Jan 20, 2006 2:04 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
I might be missing something, but wouldn't this work?

Code:
public abstract class GenericUser {
private String userName;

public String getUserName() { ... }

public void setUserName() { ... }
}

// Then, for an application specific user
public class ApplicationAUser extends GenericUser {
private String firstName;
private String lastName;
...
...
}



Then, in your DAO

Code:
public class SomeDAO {
public boolean isEmailSent(GenericUser user, EmailThing email) {
  Session session = ...;
  Query query = session.createQuery("select count(*) from UserEmailThing et where et.user.name = :userName and et.email.id = :emailID");
  query.setString("userName", user.getUserName());
  ...
  ...
}
}


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 20, 2006 2:11 pm 
Beginner
Beginner

Joined: Fri Oct 28, 2005 12:26 pm
Posts: 21
If you want to extend the class in your Hibernate mappings, you may want to join this discussion.

http://forum.hibernate.org/viewtopic.php?t=954388


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.