Discussion:
[Middlegen-user] hibernateDAO failing to generate findBy method for primary key
ian
2005-01-19 01:27:38 UTC
Permalink
I'm trying to use Middlegen 2.1's hibernate plugin to generate DAO java
source. The hibernateDAO task generates some DAO class sources, but
they're all missing kind of an obvious useful method like getById() or
findById() or load() or whatever you want to call it; the method that
gets an object by its id. It's as if hibernateDAO decided not to
generate a method for id because it is the primary key or something.
Ben Litchfield
2005-01-22 19:04:18 UTC
Permalink
Fixed now! I would love to hear some more comments on the hibernateDAO
piece, right now it is quite plain.

My goal is not not have every possible combination of methods generated,
but if we could get like 70%(save/delete/findByPK, findBySingleColumn)

What else would you like to see?

Ben
Post by ian
I'm trying to use Middlegen 2.1's hibernate plugin to generate DAO java
source. The hibernateDAO task generates some DAO class sources, but
they're all missing kind of an obvious useful method like getById() or
findById() or load() or whatever you want to call it; the method that
gets an object by its id. It's as if hibernateDAO decided not to
generate a method for id because it is the primary key or something.
-------------------------------------------------------
The SF.Net email is sponsored by: Beat the post-holiday blues
Get a FREE limited edition SourceForge.net t-shirt from ThinkGeek.
It's fun and FREE -- well, almost....http://www.thinkgeek.com/sfshirt
_______________________________________________
middlegen-user mailing list
https://lists.sourceforge.net/lists/listinfo/middlegen-user
Ray Tayek
2005-01-25 02:25:18 UTC
Permalink
-----Original Message-----
Of Ben Litchfield
Sent: Saturday, January 22, 2005 1:03 PM
Subject: Re: [Middlegen-user] hibernateDAO failing to
generate findBy method for primary key
... I would love to hear some more comments on the
hibernateDAO> piece
My goal is not not have every possible combination of methods
generated, but if we could get like 70%(save/delete/findByPK,
findBySingleColumn)
What else would you like to see?
pm4jih, i have not used middlegen for a while (and that was just to
reverse). But was trying to learn how to write dao's. I ended up with a pair
of inerfaces (please see below). I am a newbie to this stuff, and all of
this will have problems trying to be abstracted above hibernate in to dao
(for spring) and I'm sure it contains more than your 70% goal. This was for
a real anemic domain model (1 pojo - 1 table), so take it with a grain of
salt. But it does seem like mostly boilerplate and helper methods, so maybe
some of methods might be candidates for your 70%.

thanks


package dsl.hibernate;
import java.io.Serializable;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.type.Type;
public interface HTableDAO extends HDAO {
List findField(final String fieldReference) throws
HibernateException;
List findByMatchingStringField(final String fieldReference,final
Object value) throws HibernateException;
List findByMatchingField(final String fieldReference,final Object
value,final Type type) throws HibernateException;
List findFieldAndPk(final String feldReference,final Serializable
key) throws HibernateException;
int deleteByKey(final Integer key) throws HibernateException;
int deleteAll() throws HibernateException;
List findAll() throws HibernateException;
List findAllKeys() throws HibernateException;
}


package dsl.hibernate;
import java.io.Serializable;
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
public interface HDAO {
String keyFieldReference();
Type keyFieldType();
Object load(final Object object,final Serializable key) throws
HibernateException;
Object get(final Class clazz,final Serializable key) throws
HibernateException;
Object load(final Class clazz,final Serializable key) throws
HibernateException;
int size(final net.sf.hibernate.Session session,final Collection
collection) throws HibernateException;
void save(Object object) throws HibernateException;
void update(Object object) throws HibernateException;
void save(Collection c) throws HibernateException;
List find(final String hql) throws HibernateException;
List find(final String hql,final Object value,final Type type)
throws HibernateException;
List findFieldAndPk(final Class clazz,final String
feldReference,final Serializable key) throws HibernateException;
List find(final String hql,final Object[] value,final Type[] type)
throws HibernateException;
void delete(Object object) throws HibernateException;
void delete(Collection c) throws HibernateException;
int delete(final String hql) throws HibernateException;
int delete(final String hql,final Object value,final Type type)
throws HibernateException;
int deleteByKey(final Class clazz,final Serializable key) throws
HibernateException;
int delete(final String hql,final Object[] value,final Type[] type)
throws HibernateException;
int deleteAll(final Class clazz) throws HibernateException;
List findFieldValues(final String fieldReference,final Class clazz)
throws HibernateException;
List findByMatchingStringField(final Class clazz,final String
fieldReference,final Object value) throws HibernateException;
List findByMatchingField(final Class clazz,final String
fieldReference,final Object value,final Type type) throws
HibernateException;
List findAll(final Class clazz) throws HibernateException;
List findAllKeys(final Class clazz) throws HibernateException;
Serializable lastKey(final List keys) throws Exception;
Serializable newKey(final List keys) throws Exception;
List getKeys(final Class clazz);
List setKeys(final Class clazz,final List keys);
Hib h();
}

Loading...